lelit/pglast

Standard printer for CREATE TABLE statements raises error if parent_node is None

azazel75 opened this issue · 1 comments

I'm unboxing the parsed statements after parse_sql() to have less layers (of still unknown apis) and i'm trying to print a CreateStmt reboxed just into a pglast.node.Node instance. This is the relevant part of the traceback:

  File "/home/azazel/wip/my/my-network/my-network-db/dump.py", line 69, in format_stmt
    return is_(pglast.Node(stmt))
  File "/home/azazel/wip/my/my-network/my-network-db/.venv/lib/python3.7/site-packages/pglast/printer.py", line 258, in __call__
    self.print_node(statement)
  File "/home/azazel/wip/my/my-network/my-network-db/.venv/lib/python3.7/site-packages/pglast/printer.py", line 429, in print_node
    printer(node, self)
  File "/home/azazel/wip/my/my-network/my-network-db/.venv/lib/python3.7/site-packages/pglast/printers/ddl.py", line 1955, in create_stmt
    if node.parent_node.node_tag == 'CreateForeignTableStmt':
AttributeError: 'NoneType' object has no attribute 'node_tag'

The fix is trivial, but maybe for some reason you would prefer for the submitted
statement to always be wrapped at least into a pglast.ast.RawStmt and enforce
that? Boh

In the meantime I'll rewrap it before passing it to the pglast.printer.IndentedStream, first into such RawStmt and then into a Node.

lelit commented

Thank you for the report, this is now fixed in the just released v3.0.dev2: you should be able to pass concrete ast.Node subclasses to IndentedStream.__call__(), and thus avoid the steps you mentioned in the last sentence.