Raise an exception when a viewonly relationship is written to
Issue #1147
new
(original reporter: ged) It would be nice if this safeguard was implemented... And by the way, shouldn't the examples at: http://www.sqlalchemy.org/docs/05/mappers.html#advdatamapping_relation_customjoin http://www.sqlalchemy.org/docs/05/mappers.html#advdatamapping_relation_customjoin_multiplejoin be set as viewonly?
Comments (1)
-
repo owner - Log in to comment
the "boston/new york" examples are writable. You just might get back something different than what you put in if you don't respect the constraints of the primary join condition (but all elements would be persisted nonetheless).
its not cut and dry that viewonly=True's are also read only. They are populated by backrefs (for which we could make an exception case) and also can trigger the population of a non-viewonly backref (for which a "you're not allowed to append" assertion gets in the way). SQLA doesn't like to get involved with assertions at the instance manipulation level in any case. It might be a more interesting assertion at flush time instead but that doesn't really solve any complexity, just sort of "moves" it out of the attributes package which might be nice.
An "only appendable by the ORM" collection can be easily constructed using a custom collection class which is read only, except for private append and remove methods which are marked using the collections API.