You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This might be a very edgy edge case, but it goes as follows:
I'm using sqlalchemy_utils.i18ntranslation_hybrid in my application to provide translations for some of the fields in my models. Since I use them quite often, I created Mixins that define them. Since the name of the columns is not defined in the mixin directly, it has to be defined via the @declared_attr decorator. This (I suspect) causes the name of the attribute to not be available in the settable_attributes property of the class (it only shows getter), which, in turn, causes create to fail when such an attribute is provided as kwarg.
My mixin sample code:
classNameMixin:
"""This mixin is used to add a translatable name column to a table."""name_tr=Column(MutableDict.as_mutable(JSONB))
@declared_attrdefname(cls):
returntranslation_hybrid(cls.name_tr)
Hi @omrihar !
I believe in your case you can just use wn = WithName(name='Omri'); session.add(wn); session.commit() . It seems sqlalchemy_utils.i18n has some magic not compatible with sqlalchemy_mixins. Anyway, I appreciate all pull requests you can make to fix it (I don't have enough time for now) :)
This might be a very edgy edge case, but it goes as follows:
I'm using
sqlalchemy_utils.i18n
translation_hybrid
in my application to provide translations for some of the fields in my models. Since I use them quite often, I created Mixins that define them. Since the name of the columns is not defined in the mixin directly, it has to be defined via the@declared_attr
decorator. This (I suspect) causes the name of the attribute to not be available in thesettable_attributes
property of the class (it only showsgetter
), which, in turn, causescreate
to fail when such an attribute is provided askwarg
.My mixin sample code:
Now given a class:
This will not work:
But this will work:
And this is what printing
settable_attributes
gives me:Hope this help - I don't know how many people my stumble upon this, but I thought it's better to report and perhaps find a nice solution for this...
EDIT:
Using
wn = WithName(name='Omri'); session.add(wn); session.commit()
does work!The text was updated successfully, but these errors were encountered: