On Feb 18, 2014, at 4:59 AM, Adrian <adrian.schre...@gmail.com> wrote:

> 
> Hi guys,
> 
> After updating to 0.9.2 from 0.8 my custom compiles() are not working any 
> longer. The definition looks likes this:
> 
> @compiles(PrimaryKeyConstraint, "postgresql")
> def add_pg_primary_key_options(constraint, compiler, **kwargs):
>     ddl = compiler.visit_primary_key_constraint(constraint, **kwargs)
> 
>     if 'postgresql_fillfactor' in constraint.kwargs:
>         fillfactor = constraint.kwargs.get('postgresql_fillfactor')
> 
>         pos = ddl.index(')') + 1
>         ddl = ddl[:pos] + " WITH (FILLFACTOR=%s)" % fillfactor + ddl[pos:]
> 
>     return ddl
> But now I get this error: 
> 
> sqlalchemy.exc.ArgumentError: Argument 'postgresql_fillfactor' is not 
> accepted by dialect 'postgresql' on behalf of <class 
> 'sqlalchemy.sql.schema.PrimaryKeyConstraint'>
> 
> It seems the function itself is not executed at all. Are there any changes in 
> 0.9+ I am not aware of that changed the compiles() behavior?

your function is fine but the issue is that PrimaryKeyConstraint here is 
checking on that argument and raising right in the constructor, as we now check 
on those arguments (see 
http://docs.sqlalchemy.org/en/latest/changelog/changelog_09.html#change-2df4f7fe29c0f5aa2f957f4a89b0d74d
 ).

two options here are to add it in as an argument:

from sqlalchemy.dialects.postgresql import base
base.PGDialect.construct_arguments.append((PrimaryKeyConstraint, {"fillfactor": 
None}))

pk = PrimaryKeyConstraint('a', info=dict(postgresql_fillfactor='x'))

note the above should be considered a workaround; I should add an API feature 
to support adding new arguments to dialects here.  for now the above call has 
to be before any schema objects are constructed or it won’t take effect.

the other option is to use .info instead (the inconvenience here is that ‘info’ 
isn’t accepted in the constructor…):

@compiles(PrimaryKeyConstraint, "postgresql")
def add_pg_primary_key_options(constraint, compiler, **kwargs):
    ddl = compiler.visit_primary_key_constraint(constraint, **kwargs)

    if 'postgresql_fillfactor' in constraint.info:
        fillfactor = constraint.info.get('postgresql_fillfactor')

        pos = ddl.index(')') + 1
        ddl = ddl[:pos] + " WITH (FILLFACTOR=%s)" % fillfactor + ddl[pos:]

    return ddl

pk = PrimaryKeyConstraint('a')
pk.info['postgresql_fillfactor'] = 'x'




> 
> Thanks,
> 
> Adrian
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/groups/opt_out.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to