alembic_utils icon indicating copy to clipboard operation
alembic_utils copied to clipboard

Function signature parsing in drop statement fails if param name includes "default"

Open olirice opened this issue 4 years ago • 0 comments

https://github.com/olirice/alembic_utils/blob/2e9cce207b3a3ef29871c7ddeffd8d2dc1796f0d/src/alembic_utils/pg_function.py#L92

This breaks when when a parameter name includes the word "default"

e.g.

jsonb_array_elements(arr jsonb, default_arr jsonb = '[]')
from parse import parse
template = "{function_name}({parameters})"
result = parse(template, self.signature, case_sensitive=False)
function_name = result["function_name"]
parameters_str = result["parameters"].strip()
parameters: List[str] = parameters_str.split(",")

# HERE      
parameters = [x[: len(x.lower().split("default")[0])] for x in parameters]
# Output
# [['arr jsonb'], [' ', "_arr jsonb = '[]'"]] 
# Note: the leading space gets split into its own element

olirice avatar May 24 '21 17:05 olirice