- changed title to Got "AttributeError: uselist" when using association proxy and deriving from ConcreteBase
Got "AttributeError: uselist" when using association proxy and deriving from ConcreteBase
I saw a similar-looking issue here: https://bitbucket.org/zzzeek/sqlalchemy/issues/3397/association-proxy-any-on-o2m-non-object. But that one was resolved, and upon closer inspection the problem seems different. Here's my error:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "<string>", line 4, in __init__
File "/home/brian/.virtualenvs/flask-permissions-ex/lib/python3.4/site-packages/sqlalchemy/orm/state.py", line 306, in _initialize_instance
manager.dispatch.init_failure(self, args, kwargs)
File "/home/brian/.virtualenvs/flask-permissions-ex/lib/python3.4/site-packages/sqlalchemy/util/langhelpers.py", line 60, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File "/home/brian/.virtualenvs/flask-permissions-ex/lib/python3.4/site-packages/sqlalchemy/util/compat.py", line 184, in reraise
raise value
File "/home/brian/.virtualenvs/flask-permissions-ex/lib/python3.4/site-packages/sqlalchemy/orm/state.py", line 303, in _initialize_instance
return manager.original_init(*mixed[1:], **kwargs)
File "/home/brian/code/pwm/flask-permissions-ex/ex/database.py", line 28, in __init__
UserMixin.__init__(self, roles)
File "<string>", line 6, in __init__
File "/home/brian/code/pwm/flask-permissions/flask_permissions/models.py", line 125, in __init__
self.roles = [default_role]
File "/home/brian/.virtualenvs/flask-permissions-ex/lib/python3.4/site-packages/sqlalchemy/ext/associationproxy.py", line 272, in __set__
if self.scalar:
File "/home/brian/.virtualenvs/flask-permissions-ex/lib/python3.4/site-packages/sqlalchemy/util/langhelpers.py", line 754, in __get__
obj.__dict__[self.__name__] = result = self.fget(obj)
File "/home/brian/.virtualenvs/flask-permissions-ex/lib/python3.4/site-packages/sqlalchemy/ext/associationproxy.py", line 232, in scalar
scalar = not self._get_property().uselist
File "/home/brian/.virtualenvs/flask-permissions-ex/lib/python3.4/site-packages/sqlalchemy/util/langhelpers.py", line 840, in __getattr__
return self._fallback_getattr(key)
File "/home/brian/.virtualenvs/flask-permissions-ex/lib/python3.4/site-packages/sqlalchemy/util/langhelpers.py", line 818, in _fallback_getattr
raise AttributeError(key)
AttributeError: uselist
And here's the class deriving from ConcreteBase:
class UserMixin(db.Model, ConcreteBase):
"""
Subclass this for your user class
"""
__tablename__ = 'fp_user'
id = db.Column(db.Integer, primary_key=True)
_roles = db.relationship(
'Role', secondary=user_role_table, backref='users', uselist=True)
type = db.Column(db.String(50))
roles = association_proxy('_roles', 'name', creator=_role_find_or_create)
__mapper_args__ = {
'polymorphic_identity': 'usermixin',
'polymorphic_on': type
'concrete': True
}
def __init__(self, roles=None, default_role='user'):
# If only a string is passed for roles, convert it to a list containing
# that string
if roles and isinstance(roles, basestring):
roles = [roles]
# If a sequence is passed for roles (or if roles has been converted to
# a sequence), fetch the corresponding database objects and make a list
# of those.
if roles and is_sequence(roles):
self.roles = roles
# Otherwise, assign the default 'user' role. Create that role if it
# doesn't exist.
elif default_role:
self.roles = [default_role]
I tried specifying uselist=True
as shown above, and that didn't make a difference.
Comments (6)
-
reporter -
reporter - edited description
-
reporter - edited description
-
reporter - edited description
-
repo owner hello -
Please provide a complete verifiable example. Refer the guidelines at http://stackoverflow.com/help/mcve which indicate what I'd need to know the origin of your stack trace, thanks!
-
repo owner - changed status to closed
I'm assuming this error is from a subclass of UserMixin and in fact that relationship isn't there, because relationships don't inherit across concrete classes (see http://docs.sqlalchemy.org/en/rel_1_0/orm/inheritance.html#relationships-with-concrete-inheritance). Post an mcve to the mailng list if you need assistance, thanks!
- Log in to comment