Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions bitfield/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,22 @@ def get_label(self, flag):
Database.extensions.register_adapter(BitHandler, lambda x: Database.extensions.AsIs(int(x)))
except ImproperlyConfigured:
pass

# psycopg3 adapter registration: register a dumper that
# encodes Bit/BitHandler as BIGINT so parameters are typed correctly.
try:
from psycopg import adapters
from psycopg.adapt import Dumper
except Exception:
pass
else:

class _BitLikeDumper(Dumper):
# OID 20 is int8 (BIGINT) in PostgreSQL, matching Django's BigIntegerField
oid = 20

def dump(self, obj):
return str(int(obj)).encode()

adapters.register_dumper(Bit, _BitLikeDumper)
adapters.register_dumper(BitHandler, _BitLikeDumper)
17 changes: 14 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,40 @@
# Taken from:
# https://docs.djangoproject.com/en/dev/faq/install/#what-python-version-can-i-use-with-django
envlist =
py{38,39,310}-django{32,40,41}-{sqlite,postgres},
py{38,39,310,311}-django{41}-{sqlite,postgres},
py{38,39,310}-django{32,40,41}-{sqlite,postgres-psycopg2},
py{38,39,310,311,312}-django{41,42}-{sqlite,postgres-psycopg2},
py{310,311,312}-django{50,51,52}-{sqlite,postgres-psycopg3}

[gh-actions]
python =
3.8: py38
3.9: py39
3.10: py310
3.11: py311
3.12: py312

[testenv]
commands =
py.test
passenv = DB
deps =
pytest
psycopg2-binary>=2.8
psycopg2: psycopg2-binary>=2.8
psycopg3: psycopg[binary]>=3.1
django32: Django>=3.2,<3.3
django32: pytest-django>=4.2
django40: Django>=4.0,<4.1
django40: pytest-django>=4.5
django41: Django>=4.1,<4.2
django41: pytest-django>=4.5
django42: Django>=4.2,<4.3
django42: pytest-django>=4.5
django50: Django>=5.0,<5.1
django50: pytest-django>=4.5
django51: Django>=5.1,<5.2
django51: pytest-django>=4.5
django52: Django>=5.2,<5.3
django52: pytest-django>=4.5
setenv =
sqlite: DB=sqlite
postgres: DB=postgres