Read-only properties not as friendly with hybrid properties

Issue #2353 resolved
Former user created an issue

The documentation means that synonym_for has been superseded by hybrid_properties, so I tried to use that to implement a property that should not be assignable:

class MyModel(BaseObject):
    _token = Column(String)

    @hybrid_property
    def token(self):
        return self._token

When trying to assign a value to the property an exception is raised:

  File "/eggs/SQLAlchemy-0.7.3-py2.7-linux-x86_64.egg/sqlalchemy/ext/hybrid.py", line 468, in __set__
    self.fset(instance, value)
TypeError: 'NoneType' object is not callable

This exposes an implemenation detail of SQLAlchemy (fset is None). I would prefer something a bit closer to how a standard property behaves:

Traceback (most recent call last):
  File "x.py", line 7, in <module>
    a.token = 1
AttributeError: can't set attribute

this makes it obvious what you are doing something wrong, instead of wondering what is happening inside SQLAlchemy.

Comments (3)

  1. Log in to comment