Hi.

Michael Bayer wrote:
> the error that seems to be popular this week is related to people 
> trying to add foreign keys to reflected tables; we dont have unit 
> tests set up for this yet so its likely that the tables are getting 
> conflicting column objects set up.  the reason it probably doesnt work 
> at the table reflection level is because the initalization of the 
> ForeignKey object results in an "autoload" of the related table; and 
> it probably doesnt set itself up properly, and/or when you later go 
> and explcitly autoload the related table, it gets itself confused 
> somehow.
>
> you might want to try defining all of your tables first before 
> defining any mappers...that way when the Mapper gets a hold of the 
> table, it has the latest listing of Column objects on the Table.  then 
> again that might not fix it.
>
> the error generally means that the Column object which the Mapper 
> pulls off the Table at flush time is not the same Column object which 
> the mapper had at initialization time, when it first matched up each 
> Column to an attribute on the mapped class (which is represented in 
> the Mapper via a ColumnProperty).
>
> as a last resort you might have to forego the "autoload" flag (or use 
> explicit primaryjoin/secondaryjoin args on each mapper) until i have 
> time to insure that reflection deals with newly or re-defined foreign 
> keys smoothly.  

Dropping autoload for the relevant table solved the problem for me. 
Thank you very much!

Now, on to the next (and hopefully the last) one, if I may be so bold. :-)

I've stumbled upon the following error:

sqlalchemy.exceptions.FlushError: Circular dependency detected {Kamera 
Objektiv Speil -> Objektiver  (idself=1082808684): {Kamera Objektiv 
Speil  (idself=1082808204): True}, Kamera Objektiv Speil  
(idself=1082808204): {Kamera Objektiv Speil -> Objektiver  
(idself=1082808684): True}}[]

That is, SA thinks that the parent row depends on the child row, and 
vice versa, when in fact only the child depends on the parent.

I've checked the actual objects, and there are no real circular 
dependencies, that is, no row has itself as an ancestor.

Here is (part of) the table SA is working with.

Table('categories',
BoundMetaData(),
Column('categories_id',<sqlalchemy.databases.mysql.MSInteger object at 
0x4060a5ec>,key='categories_id',primary_key=True,nullable=False,hidden=False,default=None,onupdate=None),
Column('parent_id',<sqlalchemy.types.Integer object at 
0x4060742c>,ForeignKey('categories.categories_id'),key='parent_id',primary_key=False,nullable=True,hidden=False,default=None,onupdate=None),
[snip uninteresting columns]
schema=None)

The mapper:

    sa.mapper(
        Category, categories, properties=dict(
            children=sa.relation(
                Category, backref=sa.backref('parent', uselist=False)
            ),
            [snip]
        )
    )

Is there anything special I have to do to tell SA that the dependency 
should only go one way?


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to