tortoise / tortoise/tortoise-orm

Blob field (BinaryField) may not works

Open
#539 7 comments 2 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.