On Wednesday, April 20, 2016 at 3:38:01 PM UTC+2, Mike Bayer wrote:
you can put "id" in declared_attr, should work:
class Model(Base):
@declared_attr
def id(cls):
return Column(Integer, Sequence(cls.__tablename__ +
"id_seq"), ...)
Id does not work due to "sqlalchemy.exc.ArgumentError: Column-based
expression object expected for argument 'remote_side'; got:
'<sqlalchemy.ext.declarative.api.declared_attr object at
0x7f6b0a6b8870>', type <class
'sqlalchemy.ext.declarative.api.declared_attr'>" error. It looks like
remote_side is not aware of declared_attr. Should it be?
Traceback (most recent call last):
File
"/opt/pycharm/pycharm-2016.1.2/helpers/pycharm/pycharm_load_entry_point.py",
line 12, in <module>
sys.exit(f())
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/pyramid/scripts/pserve.py",
line 60, in main
return command.run()
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/pyramid/scripts/pserve.py",
line 367, in run
global_conf=vars)
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/pyramid/scripts/pserve.py",
line 402, in loadapp
return loadapp(app_spec, name=name, relative_to=relative_to, **kw)
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/paste/deploy/loadwsgi.py",
line 247, in loadapp
return loadobj(APP, uri, name=name, **kw)
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/paste/deploy/loadwsgi.py",
line 272, in loadobj
return context.create()
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/paste/deploy/loadwsgi.py",
line 710, in create
return self.object_type.invoke(self)
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/paste/deploy/loadwsgi.py",
line 203, in invoke
app = context.app_context.create()
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/paste/deploy/loadwsgi.py",
line 710, in create
return self.object_type.invoke(self)
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/paste/deploy/loadwsgi.py",
line 146, in invoke
return fix_call(context.object, context.global_conf,
**context.local_conf)
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/paste/deploy/util.py",
line 55, in fix_call
val = callable(*args, **kw)
File "/home/piotr/projects/kotti/kotti/__init__.py", line 188, in main
initialize_sql(engine)
File "/home/piotr/projects/kotti/kotti/resources.py", line 885, in
initialize_sql
populate()
File "/home/piotr/projects/kotti/kotti/populate.py", line 47, in populate
if DBSession.query(Node.id).count() == 0:
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/sqlalchemy/orm/scoping.py",
line 157, in do
return getattr(self.registry(), name)(*args, **kwargs)
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/sqlalchemy/orm/session.py",
line 1260, in query
return self._query_cls(entities, self, **kwargs)
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/sqlalchemy/orm/query.py",
line 110, in __init__
self._set_entities(entities)
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/sqlalchemy/orm/query.py",
line 120, in _set_entities
self._set_entity_selectables(self._entities)
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/sqlalchemy/orm/query.py",
line 137, in _set_entity_selectables
ext_info.mapper._equivalent_columns
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/sqlalchemy/orm/query.py",
line 153, in _mapper_loads_polymorphically_with
for m2 in mapper._with_polymorphic_mappers or [mapper]:
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py",
line 754, in __get__
obj.__dict__[self.__name__] = result = self.fget(obj)
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/sqlalchemy/orm/mapper.py",
line 1893, in _with_polymorphic_mappers
configure_mappers()
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/sqlalchemy/orm/mapper.py",
line 2768, in configure_mappers
mapper._post_configure_properties()
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/sqlalchemy/orm/mapper.py",
line 1710, in _post_configure_properties
prop.init()
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/sqlalchemy/orm/interfaces.py",
line 183, in init
self.do_init()
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/sqlalchemy/orm/relationships.py",
line 1628, in do_init
self._process_dependent_arguments()
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/sqlalchemy/orm/relationships.py",
line 1683, in _process_dependent_arguments
util.to_column_set(self.remote_side))
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/sqlalchemy/orm/relationships.py",
line 1682, in <genexpr>
for x in
File
"/home/piotr/.virtualenvs/kotti/lib/python2.7/site-packages/sqlalchemy/sql/elements.py",
line 3820, in _only_column_elements
"'%s'; got: '%s', type %s" % (name, element, type(element)))
sqlalchemy.exc.ArgumentError: Column-based expression object expected
for argument 'remote_side'; got:
'<sqlalchemy.ext.declarative.api.declared_attr object at
0x7f6b0a6b8870>', type <class
'sqlalchemy.ext.declarative.api.declared_attr'>