Skip to content

Fix automatic hstore extension creation not working on Django 4.2 or newer #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2024
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)