Column type string raises error when used as unique and searched for
Messinger opened this issue · 1 comments
Release: Rom 1.0.3
When using a String column as unique and try to search for it raises an error:
class TestR(rom.Model):
teststr=rom.String(unique=True)
tr = TestR(teststr="abcd")
tr.save()
TestR.get_by(teststr="abcd")
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/XXXX/lib/python3.9/site-packages/rom/model.py", line 640, in get_by
qvalues = list(map(cls._columns[attr]._to_redis, value))
File "/XXXX/python3.9/site-packages/rom/columns.py", line 566, in _to_redis
return value.decode('latin-1')
AttributeError: 'str' object has no attribute 'decode'
When using "Text" as type instead it works as expected, when patching columns.py avoiding the - useless - decode it is working, too.
I think column type "String" should be nothing else than an alias to column type Text... or the column "String" should check for existence of "decode", too. (new projects will not use python2 anymore)
Please read the docs for the String
and Text
Columns here:
https://josiahcarlson.github.io/rom/columns.html#rom.columns.String - "A plain string column (str in 2.x, bytes in 3.x)."
https://josiahcarlson.github.io/rom/columns.html#rom.columns.Text - "A unicode string column. Behavior is more or less identical to the String column type, except that unicode is supported (unicode in 2.x, str in 3.x)."
This is as intended, and has been the case for many revisions. Please check closed bugs for similar / identical questions in the future.
Thank you.