Hi,
I have a table-mapped attribute that is dependent on two other
attributes:
from sqlalchemy import Table, MetaData, Column, Text, create_engine,
Integer
from sqlalchemy.orm import mapper, synonym
class Foo(object):
def _get_name(self):
return self._name
def _set_name(self, name):
self._name = name
self._update_table_name()
name = property(_get_name, _set_name)
def _get_provider(self):
return self._provider
def _set_provider(self, provider):
self._provider = provider
self._update_table_name()
provider = property(_get_provider, _set_provider)
def _update_table_name(self):
table_name = "%s_%s" % (self.provider, self.name)
if len(table_name) > 50:
table_name = table_name[0:50]
self.table_name = table_name
foo_table = Table('foo', MetaData(),
Column('id', Integer, primary_key=True),
Column('name', Text),
Column('provider', Text),
Column('table_name', Text)
)
mapper(Foo, foo_table, properties={
'name' : synonym('_name', map_column=True),
'provider': synonym('_provider', map_column=True),
})
e = create_engine('sqlite:///:memory:')
foo_table.metadata.create_all(bind=e)
When I run this normally, nothing happens. When I run it under the
debugger (in PyDev), I get infinite recursion, looking like this:
Traceback (most recent call last):
File "/Applications/eclipse/plugins/
org.python.pydev.debug_1.4.4.2636/pysrc/pydevd.py", line 883, in
<module>
debugger.run(setup['file'], None, None)
File "/Applications/eclipse/plugins/
org.python.pydev.debug_1.4.4.2636/pysrc/pydevd.py", line 712, in run
execfile(file, globals, locals) #execute the script
File "/Users/gthb/Documents/workspace/test/src/sqlalchemytest7.py",
line 33, in <module>
'provider': synonym('_provider', map_column=True),
File "/path/to/SQLAlchemy/sqlalchemy/orm/__init__.py", line 752, in
mapper
return Mapper(class_, local_table, *args, **params)
File "/path/to/SQLAlchemy/sqlalchemy/orm/mapper.py", line 198, in
__init__
self._configure_properties()
File "/path/to/SQLAlchemy/sqlalchemy/orm/mapper.py", line 481, in
_configure_properties
self._configure_property(key, prop, False)
File "/path/to/SQLAlchemy/sqlalchemy/orm/mapper.py", line 616, in
_configure_property
prop.instrument_class(self)
File "/path/to/SQLAlchemy/sqlalchemy/orm/properties.py", line 302,
in instrument_class
proxy_property=self.descriptor
File "/path/to/SQLAlchemy/sqlalchemy/orm/attributes.py", line 1590,
in register_descriptor
descriptor = proxy_type(key, proxy_property, comparator,
parententity)
File "/path/to/SQLAlchemy/sqlalchemy/orm/attributes.py", line 181,
in __init__
self.descriptor = self.user_prop = descriptor
File "/Users/gthb/Documents/workspace/test/src/sqlalchemytest7.py",
line 14, in _set_name
self._update_table_name()
File "/path/to/SQLAlchemy/sqlalchemy/orm/attributes.py", line 214,
in __getattr__
return getattr(self._comparator, attribute)
File "/path/to/SQLAlchemy/sqlalchemy/orm/attributes.py", line 214,
in __getattr__
return getattr(self._comparator, attribute)
....
The same can be reproduced outside of PyDev by doing:
python -m pdb sqlalchemytest7.py
and stepping until the above calamity strikes. (It seems it does not
happen on cont)
This is in python 2.5.2 on Mac OS X 10.5.6, with sqlalchemy 0.5.2.
So, two things:
1) what am I doing wrong?
2) SQLAlchemy should handle it more gracefully. :)
Regards,
- Gulli
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---