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

Can't use @propertys on Entities #21

Open
six8 opened this issue Oct 5, 2018 · 0 comments
Open

Can't use @propertys on Entities #21

six8 opened this issue Oct 5, 2018 · 0 comments

Comments

@six8
Copy link
Collaborator

six8 commented Oct 5, 2018

Python's __setattr__ has precedence over descriptors like @property. If you do, you'll get:

  File "/python2.7/site-packages/springfield/entity.py", line 203, in __setattr__
    raise AttributeError('Field %r not defined.' % name)

Entity needs to be modified to allow properties:

if name in self.__fields__ or isinstance(getattr(self.__class__, name, None), property):
    object.__setattr__(self, name, value)
else:
    raise AttributeError('Field %r not defined.' % name)

As a workaround, the following can be added to any Entity to support properties:

def __setattr__(self, name, value):
        if name not in self.__fields__ and isinstance(getattr(self.__class__, name, None), property):
            object.__setattr__(self, name, value)
        else:
            super(EntityName, self).__setattr__(name, value)
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