Re: [Django] #36101: Support BIT data type model field for MySQL and PostgreSQL

5 views
Skip to first unread message

Django

unread,
Jan 15, 2025, 12:57:43 PM1/15/25
to django-...@googlegroups.com
#36101: Support BIT data type model field for MySQL and PostgreSQL
-------------------------------------+-------------------------------------
Reporter: Jordan Bae | Owner: (none)
Type: New feature | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* resolution: => wontfix
* status: new => closed

Comment:

I'm not convinced that we should add a dedicated field for this given we
already have the all purposed `BinaryField`
[https://docs.djangoproject.com/en/5.1/ref/models/fields/#binaryfield
which I don't see mentioned in your report] implemented as `longblob` on
[https://github.com/django/django/blob/0cabed9efa2c7abd1693860069f20ec5db41fcd8/django/db/backends/mysql/base.py#L111
MySQL] and `bytea`
[https://github.com/django/django/blob/0cabed9efa2c7abd1693860069f20ec5db41fcd8/django/db/backends/postgresql/base.py#L99
on Postgres] which should cover most of the usage a `BitField` would have.

> Improved Database Inspection

This argument could stand for pretty much any type that database support
and Django doesn't have a field equivalent for.

> Efficient storage of boolean flags and bit flags

Apparently `bytea` [https://stackoverflow.com/questions/26635547
/postgresql-difference-between-bytea-and-bit-varying-types is more space
efficient] than `bit varying` on PostgreSQL so if you've reached a point
where the storage of boolean bits and flags is of a concern `BinaryField`
would be a better option on Postgres at least.

> Direct mapping to database-native bit operations

These database-native bit operations would need to be implemented as
lookups and transforms anyway on the ORM side which is something that
could be done with `BinaryField` as well.

Given that you can likely implement a `BitField` by subclassing
`BinaryField`, overriding it's `db_type`
[https://docs.djangoproject.com/en/5.1/howto/custom-model-fields/#useful-
methods method] to return `f"bit({self.max_length})"` and that adding a
`BitField` in core [https://github.com/disqus/django-bitfield/tree/master
while there are third-party alternatives] I'm would incur a significant
maintenance burden going to close this ticket as ''wontfix''.

If you disagree please create a forum discussion to try to form community
consensus on the subject
[https://docs.djangoproject.com/en/5.1/internals/contributing/writing-code
/submitting-patches/#the-django-forum-or-django-developers-mailing-list as
documented when proposing new features].
--
Ticket URL: <https://code.djangoproject.com/ticket/36101#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 15, 2025, 7:32:45 PM1/15/25
to django-...@googlegroups.com
#36101: Support BIT data type model field for MySQL and PostgreSQL
-------------------------------------+-------------------------------------
Reporter: Jordan Bae | Owner: (none)
Type: New feature | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jordan Bae):

Thanks for reviewing my suggestion. I totally understood.
--
Ticket URL: <https://code.djangoproject.com/ticket/36101#comment:3>
Reply all
Reply to author
Forward
0 new messages