Skip to content

Commit

Permalink
#1352: Repack error into more informative one when it occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalp committed Jan 26, 2023
1 parent c91b732 commit 80b5398
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions misago/users/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,42 @@ def get_short_name(self):
return self.username

def get_real_name(self):
# Bug: https://github.com/rafalp/Misago/issues/1352
# On some very rare cases self.profile_fields is deserialized as string
# by Django's ORM. I am unable to reproduce this, but in case when this
# bug occurs, this code branch will print extra information about it
if not isinstance(self.profile_fields, dict):
from django.db import connections
from django.db.backends.signals import connection_created
from django.contrib.postgres.signals import get_hstore_oids

receivers = ", ".join([str(r[1]()) for r in connection_created.receivers])
dead_receivers = "TRUE" if connection_created._dead_receivers else "FALSE"

valid_oids = None
cached_oids = get_hstore_oids("default")

with connections["default"].cursor() as cursor:
cursor.execute(
"SELECT t.oid, typarray "
"FROM pg_type t "
"JOIN pg_namespace ns ON typnamespace = ns.oid "
"WHERE typname = 'hstore'"
)
oids = []
array_oids = []
for row in cursor:
oids.append(row[0])
array_oids.append(row[1])
valid_oids = tuple(oids), tuple(array_oids)

raise RuntimeError(
f"'profile_fields' has wrong type! Please post this WHOLE message on https://github.com/rafalp/Misago/issues/1352 "
f"OID: '{cached_oids}' (valid: '{valid_oids}') "
f"Receivers: '{receivers}' (has dead: {dead_receivers}) "
f"Repr: {repr(self.profile_fields)}"
)

return self.profile_fields.get("real_name")

def set_username(self, new_username, changed_by=None):
Expand Down

0 comments on commit 80b5398

Please sign in to comment.