Skip to content

Commit

Permalink
Add HSTORE to render_type_w_subtype
Browse files Browse the repository at this point in the history
Fixed the autogenerate of the module prefix
when rendering the text_type parameter of
postgresql.HSTORE, in much the same way that
we do for ARRAY's type and JSON's text_type.

Change-Id: Ie8c2cdd1f4aeebcbb306c7f74168f8ac33688b1a
Fixes: sqlalchemy#480
  • Loading branch information
zzzeek committed Jan 26, 2018
1 parent edfccce commit d4755d5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
5 changes: 5 additions & 0 deletions alembic/ddl/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ def render_type(self, type_, autogen_context):

return False

def _render_HSTORE_type(self, type_, autogen_context):
return render._render_type_w_subtype(
type_, autogen_context, 'text_type', r'(.+?\(.*text_type=)'
)

def _render_ARRAY_type(self, type_, autogen_context):
return render._render_type_w_subtype(
type_, autogen_context, 'item_type', r'(.+?\()'
Expand Down
8 changes: 8 additions & 0 deletions docs/build/unreleased/480.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. change::
:tags: bug, postgresql
:tickets: 480

Fixed the autogenerate of the module prefix
when rendering the text_type parameter of
postgresql.HSTORE, in much the same way that
we do for ARRAY's type and JSON's text_type.
25 changes: 24 additions & 1 deletion tests/test_postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@


if util.sqla_09:
from sqlalchemy.dialects.postgresql import JSON, JSONB
from sqlalchemy.dialects.postgresql import JSON, JSONB, HSTORE


class PostgresqlOpTest(TestBase):
Expand Down Expand Up @@ -693,6 +693,29 @@ def test_postgresql_array_type(self):
assert 'from sqlalchemy.dialects import postgresql' in \
self.autogen_context.imports

@config.requirements.sqlalchemy_110
def test_postgresql_hstore_subtypes(self):
eq_ignore_whitespace(
autogenerate.render._repr_type(
HSTORE(), self.autogen_context),
"postgresql.HSTORE(text_type=sa.Text())"
)

eq_ignore_whitespace(
autogenerate.render._repr_type(
HSTORE(text_type=String()), self.autogen_context),
"postgresql.HSTORE(text_type=sa.String())"
)

eq_ignore_whitespace(
autogenerate.render._repr_type(
HSTORE(text_type=BYTEA()), self.autogen_context),
"postgresql.HSTORE(text_type=postgresql.BYTEA())"
)

assert 'from sqlalchemy.dialects import postgresql' in \
self.autogen_context.imports

@config.requirements.sqlalchemy_110
def test_generic_array_type(self):

Expand Down

0 comments on commit d4755d5

Please sign in to comment.