[Sqlalchemy-tickets] [sqlalchemy] #2338: Registration of class to declarative base with module name
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2011-12-01 14:07:55
|
#2338: Registration of class to declarative base with module name
----------------------------------------------------+-----------------------
Reporter: guest | Owner: zzzeek
Type: enhancement | Status: new
Priority: medium | Milestone:
Component: (none) | Severity: no triage selected yet
Keywords: classnames, relation, declarative base | Status_field: awaiting triage
----------------------------------------------------+-----------------------
At the moment classes which inherit Base are registered with just their
classname. When multiple classes with the same name inherit Base a warning
will appear:
{{{
SAWarning: The classname 'Class' is already in the registry of this
declarative base, mapped to <class 'path.to.Class'>
}}}
If the class was registered including the module name, so 'path.to.Class',
then it would be possible to uses classes with the same name. Of course as
long as they obey the Python rules concerning namespaces.
Example:
When a relationship is defined a string name can be used. When only one
class with this name is registered, this class can be used. If multiple
classes have the same name, the path to the class can be defined in the
string name.
Let's say we have the following relationship:
{{{
relation = relationship("Class")
}}}
If only one class with the name "Class" is registered with the declarative
base, this class can be used. If multiple classes with the name "Class"
are found, the path should be defined:
{{{
relation = relationship("path.to.Class")
}}}
When multiple classes with the same name are found and the relation
defines only the class name, an error can be raised.
{{{
Multiple classes with the classname "Class" are in the registry of this
declarative base. Please including the module name.
}}}
It would even be possible to list the classes with module names so the
user can pick the right one.
Current workarounds:
- Don't use classes with the same name with the same declarative base
- Use multiple declarative bases
- Import the class you want a relation to and refer to this. (This is not
always possible)
- Only define the relations after both classes have been declared. (This
will still give the SAWarnings.)
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2338>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|