Skip to content
Merged
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
23 changes: 23 additions & 0 deletions psqlextra/backend/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
from typing import TYPE_CHECKING

from django.conf import settings
from django.contrib.postgres.signals import (
get_hstore_oids,
register_type_handlers,
)
from django.db import ProgrammingError

from . import base_impl
Expand Down Expand Up @@ -94,3 +98,22 @@ def prepare_database(self):
"or add the extension manually.",
exc_info=True,
)
return

# Clear old (non-existent), stale oids.
get_hstore_oids.cache_clear()

# Verify that we (and Django) can find the OIDs
# for hstore.
oids, _ = get_hstore_oids(self.alias)
if not oids:
logger.warning(
'"hstore" extension was created, but we cannot find the oids'
"in the database. Something went wrong.",
)
return

# We must trigger Django into registering the type handlers now
# so that any subsequent code can properly use the newly
# registered types.
register_type_handlers(self)