Having trouble using classes in different modules with the same name with declarative setup.

29 views
Skip to first unread message

jers

unread,
Aug 21, 2012, 4:36:15 PM8/21/12
to sqlal...@googlegroups.com
To give an example I have I have two classes that have the same name, but belong to different modules.  there is an accounts.py that has a class Account(Base), and a testing.py that has a class Account(Base).

When I try to set this up I get warnings:

The classname 'Account' is already in the registry of this declarative base


Is there any way I can get around this without having to change my class names?

Michael Bayer

unread,
Aug 21, 2012, 5:19:49 PM8/21/12
to sqlal...@googlegroups.com
In 0.8, when using string-based configuration, you'll be able to refer to classes of the same name in different modules using a module-qualified pathname.    

However, this warning is harmless and only means you can't refer to those classes via string name when you use relationship().  You need to either use the class directly:

relationship(Account)

or a lambda in conjunction with making sure the calling module has Account available when all the mappings are complete:

relationship(lambda: Account)



--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/wGUh_akx25IJ.
To post to this group, send email to sqlal...@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.

jers

unread,
Aug 21, 2012, 6:27:16 PM8/21/12
to sqlal...@googlegroups.com
Good to hear, thanks!
Reply all
Reply to author
Forward
0 new messages