Skip to content

Commit

Permalink
Update psycopg2 to psycopg3
Browse files Browse the repository at this point in the history
  • Loading branch information
Uxio0 committed Jan 14, 2025
1 parent b6f24a5 commit 23f0eea
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
ports:
- 6379:6379
postgres:
image: postgres:14
image: postgres:16-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
Expand Down
2 changes: 1 addition & 1 deletion config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"default": env.db("DATABASE_URL"),
}
DATABASES["default"]["ATOMIC_REQUESTS"] = False
DATABASES["default"]["ENGINE"] = "django_db_geventpool.backends.postgresql_psycopg2"
DATABASES["default"]["ENGINE"] = "django_db_geventpool.backends.postgresql_psycopg3"
DATABASES["default"]["CONN_MAX_AGE"] = 0
DB_MAX_CONNS = env.int("DB_MAX_CONNS", default=50)
DATABASES["default"]["OPTIONS"] = {
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ services:
retries: 3

db:
image: postgres:14-alpine
image: postgres:16-alpine
ports:
- "5432:5432"
environment:
Expand Down
13 changes: 3 additions & 10 deletions gunicorn_custom_workers.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import gevent
from gunicorn.workers.ggevent import GeventWorker
from psycogreen.gevent import patch_psycopg


class MyGeventWorker(GeventWorker):
def patch_psycopg2(self):
patch_psycopg()
self.log.info("Patched Psycopg2 for gevent")

def patch(self):
super().patch()
self.log.info("Patched all for gevent")
self.patch_psycopg2()

def handle_request(self, listener_name, req, sock, addr):
"""
Add timeout for Gunicorn requests
"""
try:
with gevent.Timeout(self.cfg.timeout):
super().handle_request(listener_name, req, sock, addr)
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ packaging>=21.0
pika==1.3.2
pillow==11.0.0
psycogreen==1.0.2
psycopg2==2.9.10
psycopg[binary]==3.2.3
redis==5.2.1
requests==2.32.3
safe-eth-py[django]==6.1.0
safe-eth-py[django]==6.3.0
web3==6.20.2
2 changes: 1 addition & 1 deletion safe_transaction_service/history/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ class ModuleTransactionAdmin(AdvancedAdminSearchMixin, admin.ModelAdmin):
search_fields = ["==safe", "==module", "==to"]

def data_hex(self, o: ModuleTransaction):
return HexBytes(o.data.tobytes()).hex() if o.data else None
return HexBytes(o.data).hex() if o.data else None

def tx_hash(self, o: ModuleTransaction):
return o.internal_tx.ethereum_tx_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ def handle(self, *args, **options):
str(m.failed),
m.origin,
(
json.dumps(
decoder.get_data_decoded(m.data.tobytes())
)
json.dumps(decoder.get_data_decoded(m.data))
if m.data
else ""
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def add_signature_type(apps, schema_editor):

for multisig_tx in MultisigTransaction.objects.exclude(signatures=None):
for safe_signature in SafeSignature.parse_signature(
multisig_tx.signatures.tobytes(), HexBytes(multisig_tx.safe_tx_hash)
multisig_tx.signatures, HexBytes(multisig_tx.safe_tx_hash)
):
multisig_confirmation, _ = MultisigConfirmation.objects.get_or_create(
multisig_transaction_hash=multisig_tx.safe_tx_hash,
Expand Down
6 changes: 2 additions & 4 deletions safe_transaction_service/history/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,7 @@ class Meta:
)

def get_data_decoded(self, obj: ModuleTransaction) -> Dict[str, Any]:
return get_data_decoded_from_data(
obj.data.tobytes() if obj.data else b"", address=obj.to
)
return get_data_decoded_from_data(obj.data if obj.data else b"", address=obj.to)

def get_is_successful(self, obj: ModuleTransaction) -> bool:
return not obj.failed
Expand Down Expand Up @@ -738,7 +736,7 @@ def get_data_decoded(self, obj: MultisigTransaction) -> Dict[str, Any]:
# If delegate call contract must be whitelisted (security)
if obj.data_should_be_decoded():
return get_data_decoded_from_data(
obj.data.tobytes() if obj.data else b"", address=obj.to
obj.data if obj.data else b"", address=obj.to
)


Expand Down

0 comments on commit 23f0eea

Please sign in to comment.