Blob field (BinaryField) may not works
Describe the bug Can't query by blob fields, can't update blob values.
To Reproduce
from tortoise import Tortoise, fields, run_async
from tortoise.models import Model
class Event(Model):
id = fields.IntField(pk=True)
bin = fields.BinaryField()
class Meta:
table = "event"
def __str__(self):
return self.name
async def run():
await Tortoise.init(db_url="sqlite://:memory:", modules={"models": ["__main__"]})
await Tortoise.generate_schemas()
event = await Event.create(bin=b'aabb')
print(Event.filter(bin=b"aabb").sql())
print(await Event.filter(id=1).update(bin=b'aacc'))
if __name__ == "__main__":
run_async(run())
Expected behavior Code just works. Actually cause error.
sql generated: SELECT "id","bin" FROM "event" WHERE "bin"=b'aabb'
Additional context
docs said it. https://tortoise-orm.readthedocs.io/en/latest/fields.html#module-tortoise.fields.data
@long2ice Does tortoise-orm have any plan to support it?
After a little time search, maybe filter for blob is unnecessary
After a little time search, maybe filter for blob is unnecessary
No, it's common situation.
For example, when use a distributed id algorithm like snowflake, uuid and so on, blob field is natural choice.
class User:
id = BlobField(primary_key=True)
name = CharField()
class Topic:
title = CharField()
content = TextField()
author = BlobField()
Why not use UUIDField or CharField directly?
Why not use UUIDField or CharField directly?
CharField needs 2x space, and this will cause additional serialization and deserialization.
blob is part of sql standard, if native type works, why not use it?
still can not filter the blob