Skip to content

Commit

Permalink
introduced DJANGO_HSTORE_ADAPTER_REGISTRATION
Browse files Browse the repository at this point in the history
backward compatibility with the old setting DJANGO_HSTORE_GLOBAL_REGISTER is mantained.
The setting adds compatibility with SQLAlchemy.
closes #45
  • Loading branch information
nemesifier committed Jun 26, 2014
1 parent 1a5fb96 commit a4554b5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
29 changes: 21 additions & 8 deletions django_hstore/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,25 @@
from .utils import register_hstore


# keep backward compatibility until django hstore 1.3.0
HSTORE_GLOBAL_REGISTER = getattr(settings, "DJANGO_HSTORE_GLOBAL_REGISTER", None)

# This allows users that introduce hstore into an existing
# environment to set global registry to false in order to avoid
# unpredictable behaviors when having hstore installed individually
# environment to disable global registration of the hstore adapter
# in order to avoid unpredictable behavior when having hstore installed individually
# on each database instead of on having it installed on template1.
HSTORE_GLOBAL_REGISTER = getattr(settings, "DJANGO_HSTORE_GLOBAL_REGISTER", True)

if HSTORE_GLOBAL_REGISTER is None:
HSTORE_REGISTER_GLOBALLY = getattr(settings, "DJANGO_HSTORE_ADAPTER_REGISTRATION", "global") == "global"
else:
HSTORE_REGISTER_GLOBALLY = HSTORE_GLOBAL_REGISTER
# issue deprecation warning
import warnings
warnings.warn("""\n
DJANGO_HSTORE_GLOBAL_REGISTER setting is deprecated since django-hstore 1.2.5 and will be removed in 1.3.0.
Use DJANGO_HSTORE_ADAPTER_REGISTRATION by setting it either to 'global' or 'connection'.
""",
DeprecationWarning)


class ConnectionCreateHandler(object):
Expand All @@ -25,7 +39,6 @@ class ConnectionCreateHandler(object):
Executes attached functions when connection is created.
With possibility of attaching single execution methods.
"""

generic_handlers = []
unique_handlers = []

Expand Down Expand Up @@ -63,17 +76,17 @@ def register_hstore_handler(connection, **kwargs):
# defer hstore registration by setting up a new unique handler
if connection.settings_dict['NAME'] is None:
connection_handler.attach_handler(register_hstore_handler,
vendor="postgresql", unique=HSTORE_GLOBAL_REGISTER)
vendor="postgresql", unique=HSTORE_REGISTER_GLOBALLY)
return

if sys.version_info[0] < 3:
register_hstore(connection.connection, globally=True, unicode=True)
register_hstore(connection.connection, globally=HSTORE_REGISTER_GLOBALLY, unicode=True)
else:
register_hstore(connection.connection, globally=True)
register_hstore(connection.connection, globally=HSTORE_REGISTER_GLOBALLY)


connection_handler.attach_handler(register_hstore_handler,
vendor="postgresql", unique=HSTORE_GLOBAL_REGISTER)
vendor="postgresql", unique=HSTORE_REGISTER_GLOBALLY)


class HStoreConfig(AppConfig):
Expand Down
6 changes: 3 additions & 3 deletions doc/doc.asciidoc
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
django-hstore documentation
===========================
0.1.0, 2014-04-17
1.2.5, 2014-06-26

:toc:
:numbered:
Expand Down Expand Up @@ -71,8 +71,8 @@ if hstore extension is installed individually in each database.
To avoid this strange behavior you have two options:
- Install hstore on *template1* postgresql template database and recreate all databases/templates
from it, which allows all database to have the same oid for the hstore type (this is a recommended way).
- Disable global registering setting `DJANGO_HSTORE_GLOBAL_REGISTER` by setting it to `False` in your settings. This
from it, which allows all database to have the same oid for the hstore type (this is the recommended way).
- Disable global registering setting `DJANGO_HSTORE_ADAPTER_REGISTRATION` by setting it to `connection` in your settings. This
can have a performance impact because it registers the hstore extension for each new connection created
(if you are using django 1.6, persistent connections - or any other connection pool - will help to
reduce this impact).
Expand Down

0 comments on commit a4554b5

Please sign in to comment.