I am faced with an issue where I am trying to convert a string (in db) to a list of decimals.
My code: `
@hybrid_property
def decimals(self) -> list[Decimal]:
return [Decimal(dec) for dec in self._decimals.replace('d', '').split(';')]
@decimals.setter
def decimals(self, decimals):
self._decimals = ';'.join(str(dec) for dec in decimals)
`
I get an error 'decimals' is an invalid keyword argument
Stacktrace:
self = <app.models.models.Test_Db object at 0x000001F2A5EAA2F0>
kwargs = {'id': 0, 'connection': 'D', 'fron': 'loop feed', 'hasRail': False, ...}
cls_ = <class 'app.models.models.Test_Db'>, k = 'decimals'
def _declarative_constructor(self, **kwargs):
"""A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and
values in ``kwargs``.
Only keys that are present as
attributes of the instance's class are allowed. These could be,
for example, any mapped columns or relationships.
"""
cls_ = type(self)
for k in kwargs:
if not hasattr(cls_, k):
> raise TypeError(
"%r is an invalid keyword argument for %s" % (k, cls_.__name__)
)
E TypeError: 'decimals' is an invalid keyword argument for Test_Db
..\env\lib\site-packages\sqlalchemy\orm\decl_base.py:1154: TypeError