lelit/pglast

Printing of AlterOwnerStmt for operator class results in error.

bennieswart opened this issue · 3 comments

Consider the following on linux with python 3.11.6 and pglast 5.8:

>>> from pglast import prettify, parse_sql
>>> prettify('ALTER OPERATOR CLASS public.ean13_ops USING btree OWNER TO postgres');
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".venv/lib/python3.11/site-packages/pglast/__init__.py", line 95, in prettify
    prettified = IndentedStream(**options)(orig_pt)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/pglast/stream.py", line 200, in __call__
    self.print_node(statement)
  File ".venv/lib/python3.11/site-packages/pglast/stream.py", line 376, in print_node
    printer(node, self)
  File ".venv/lib/python3.11/site-packages/pglast/printers/dml.py", line 1238, in raw_stmt
    output.print_node(node.stmt)
  File ".venv/lib/python3.11/site-packages/pglast/stream.py", line 376, in print_node
    printer(node, self)
  File ".venv/lib/python3.11/site-packages/pglast/printers/ddl.py", line 282, in alter_owner_stmt
    method, name = node.object
    ^^^^^^^^^^^^
ValueError: too many values to unpack (expected 2)

When removing the schema qualification from the name it works as expected:

>>> prettify('ALTER OPERATOR CLASS ean13_ops USING btree OWNER TO postgres');
'ALTER OPERATOR CLASS ean13_ops USING btree OWNER TO postgres'

Here is the difference in parsing, for convenience.

>>> parse_sql('ALTER OPERATOR CLASS ean13_ops USING btree OWNER TO postgres');
(<RawStmt stmt=<AlterOwnerStmt objectType=<ObjectType.OBJECT_OPCLASS: 24> object=(<String sval='btree'>, <String sval='ean13_ops'>) newowner=<RoleSpec roletype=<RoleSpecType.ROLESPEC_CSTRING: 0> rolename='postgres'>> stmt_location=0 stmt_len=0>,)

>>> parse_sql('ALTER OPERATOR CLASS public.ean13_ops USING btree OWNER TO postgres');
(<RawStmt stmt=<AlterOwnerStmt objectType=<ObjectType.OBJECT_OPCLASS: 24> object=(<String sval='btree'>, <String sval='public'>, <String sval='ean13_ops'>) newowner=<RoleSpec roletype=<RoleSpecType.ROLESPEC_CSTRING: 0> rolename='postgres'>> stmt_location=0 stmt_len=0>,)

Thank you for the report, will check as time permits.

Ok, this is fixed in the upcoming v5.9.

Thanks. Fast as always :) Much appreciated.