Skip to content

Existing function normalization breaks when function params are unnamed #129

@Halliax

Description

@Halliax

The latest fix means that all existing functions are normalized in the line

existing_functions_by_name = {
    f.qualified_name: f.normalize() for f in existing_functions
}

When the database contains functions with unnamed parameters (e.g. func(type) ... dosomethingwith($1)) this produces a 'NoneType' object has no attribute 'lower' error:

File "/.../sqlalchemy_declarative_extensions/alembic/function.py", line 26, in _compare_functions
  result = compare_functions(autogen_context.connection, functions)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.../sqlalchemy_declarative_extensions/function/compare.py", line 60, in compare_functions
  f.qualified_name: f.normalize() for f in existing_functions
                    ^^^^^^^^^^^^^
File "/.../sqlalchemy_declarative_extensions/dialects/postgresql/function.py", line 126, in normalize
  FunctionParam.from_unknown(p).normalize() for p in self.parameters
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.../sqlalchemy_declarative_extensions/dialects/postgresql/function.py", line 195, in normalize
  name=self.name.lower(),
       ^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'lower'

It does seem to be fixed by changing the relevant line to name=self.name.lower() if self.name is not None else None, but I haven't investigated thoroughly

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions