Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to eve-sqlalchemy 0.7.1 / hybrid_property / AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with <relation> has an attribute <column> #209

Open
vr-devs opened this issue Apr 11, 2021 · 0 comments

Comments

@vr-devs
Copy link

vr-devs commented Apr 11, 2021

Hi, all!
I've faced with issue after upgrading eve-sqlalchemy from 0.4.1 to 0.7.1.
My package versions are following:

  • flask==0.12
  • sqlalchemy==1.3
  • Eve==0.7.2
  • Eve-sqlalchemy==0.7.1

One of my model has relation and hybrid_property:

class PrivateAccount:    
    _user_id = Column('_user_id')
     user = relationship('User')

    @hybrid_property
    def name(self):
        if self.user:
            return '{} {}'.format(self.user.firstname, self.user.lastname)

DOMAIN = DomainConfig({
        'private_account': ResourceConfig(PrivateAccount),
    }).render()

I got an error when domain is building

DOMAIN = DomainConfig({
  DOMAIN = DomainConfig({
File "/home/user/.pyenv/versions/test_env/lib/python3.9/site-packages/eve_sqlalchemy/config/domainconfig.py", line 63, in render
  domain_def[endpoint] = resource_config.render(
  
File "/home/user/.pyenv/versions/test_env/lib/python3.9/site-packages/eve_sqlalchemy/config/resourceconfig.py", line 58, in render
  field_configs = self._create_field_configs()
File "/home/user/.pyenv/versions/test_env/lib/python3.9/site-packages/eve_sqlalchemy/config/resourceconfig.py", line 141, in _create_field_configs
  hybrid_properties = {
File "/home/user/.pyenv/versions/test_env/lib/python3.9/site-packages/eve_sqlalchemy/config/resourceconfig.py", line 142, in <dictcomp>
  k: HybridPropertyFieldConfig(k, self.model, self._mapper)
File "/home/user/.pyenv/versions/test_env/lib/python3.9/site-packages/eve_sqlalchemy/config/fieldconfig.py", line 16, in __init__
  self._field = getattr(model, name)
File "/home/user/.pyenv/versions/test_env/lib/python3.9/site-packages/sqlalchemy/ext/hybrid.py", line 893, in __get__
  return self._expr_comparator(owner)
File "/home/user/.pyenv/versions/test_env/lib/python3.9/site-packages/sqlalchemy/ext/hybrid.py", line 1100, in expr_comparator
  comparator(owner),
File "/home/user/.pyenv/versions/test_env/lib/python3.9/site-packages/sqlalchemy/ext/hybrid.py", line 1085, in _expr
  return ExprComparator(cls, expr(cls), self)
File "/home/user/dev/test_env/models/model_private_account.py", line 71, in name
  return '{} {}'.format(self.user.firstname, self.user.lastname)
File "/home/user/.pyenv/versions/test_env/lib/python3.9/site-packages/sqlalchemy/orm/attributes.py", line 223, in __getattr__
  raise AttributeError(
AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with PrivateAccount.user has an attribute 'firstname'

As I understood hybrid properties initialized at startup unlike registerSchema mechanism (version 0.4.1).
How to avoid this issue (without using try/except)?
Maybe somebody has solved this before?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant