tortoise / tortoise/tortoise-orm
Blob field (BinaryField) may not works
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided SQLite reproduction and tracing BinaryField handling for filtering and updates. Check how blob values are represented in the generated SQL and parameters; done means querying by a blob succeeds and updating a blob value works without an error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, sqlite
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100