From a349e4090d45e8728ca2864f180aacb5f7d8a454 Mon Sep 17 00:00:00 2001 From: Oliver Rice Date: Tue, 21 May 2024 09:14:15 -0500 Subject: [PATCH 1/2] strip trailing whitespace in function name prior to parameters --- src/alembic_utils/pg_function.py | 6 +++--- src/test/test_pg_function.py | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/alembic_utils/pg_function.py b/src/alembic_utils/pg_function.py index 558093b..6646ffc 100644 --- a/src/alembic_utils/pg_function.py +++ b/src/alembic_utils/pg_function.py @@ -65,7 +65,7 @@ def literal_signature(self) -> str: """ # May already be quoted if loading from database or SQL file name, remainder = self.signature.split("(", 1) - return '"' + name + '"(' + remainder + return '"' + name.strip() + '"(' + remainder def to_sql_statement_create(self): """Generates a SQL "create function" statement for PGFunction""" @@ -79,12 +79,12 @@ def to_sql_statement_drop(self, cascade=False): template = "{function_name}({parameters})" result = parse(template, self.signature, case_sensitive=False) try: - function_name = result["function_name"] + function_name = result["function_name"].strip() parameters_str = result["parameters"].strip() except TypeError: # Did not match, NoneType is not scriptable result = parse("{function_name}()", self.signature, case_sensitive=False) - function_name = result["function_name"] + function_name = result["function_name"].strip() parameters_str = "" # NOTE: Will fail if a text field has a default and that deafult contains a comma... diff --git a/src/test/test_pg_function.py b/src/test/test_pg_function.py index e3573b1..17a71e3 100644 --- a/src/test/test_pg_function.py +++ b/src/test/test_pg_function.py @@ -1,3 +1,5 @@ +from typing import List + from sqlalchemy import text from alembic_utils.pg_function import PGFunction @@ -6,7 +8,7 @@ TO_UPPER = PGFunction( schema="public", - signature="toUpper(some_text text default 'my text!')", + signature="toUpper (some_text text default 'my text!')", definition=""" returns text as @@ -15,6 +17,19 @@ ) +def test_trailing_whitespace_stripped(): + sql_statements: List[str] = [ + str(TO_UPPER.to_sql_statement_create()), + str(next(iter(TO_UPPER.to_sql_statement_create_or_replace()))), + str(TO_UPPER.to_sql_statement_drop()), + ] + + for statement in sql_statements: + print(statement) + assert '"toUpper"' in statement + assert not '"toUpper "' in statement + + def test_create_revision(engine) -> None: register_entities([TO_UPPER], entity_types=[PGFunction]) From 629c985027dd32ab46a2d96068fce5890daddf33 Mon Sep 17 00:00:00 2001 From: Oliver Rice Date: Tue, 21 May 2024 09:14:53 -0500 Subject: [PATCH 2/2] incr version --- src/alembic_utils/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/alembic_utils/__init__.py b/src/alembic_utils/__init__.py index deded32..732155f 100644 --- a/src/alembic_utils/__init__.py +++ b/src/alembic_utils/__init__.py @@ -1 +1 @@ -__version__ = "0.8.2" +__version__ = "0.8.3"