fix(python-driver): add null-guards in ANTLR parser and relax runtime version pin by uesleilima · Pull Request #2372 · apache/age

added 2 commits

April 5, 2026 13:43
… version pin

Fix two related issues in the Python driver's ANTLR4 parsing pipeline:

1. Add null-guards in ResultVisitor methods (visitAgValue, visitFloatLiteral,
   visitPair, visitObj, handleAnnotatedValue) to prevent AttributeError crashes
   when the ANTLR4 parse tree contains None child nodes. This occurs with
   vertices that have complex properties (large arrays, special characters,
   deeply nested structures). (apache#2367)

2. Relax antlr4-python3-runtime version constraint from ==4.11.1 to
   >=4.11.1,<5.0 in both pyproject.toml and requirements.txt. The 4.11.1
   pin is incompatible with Python >= 3.13. The ANTLR ATN serialized format
   is unchanged between 4.11 and 4.13, so the generated lexer/parser files
   are compatible. Validated with antlr4-python3-runtime==4.13.2 on
   Python 3.11-3.14. (apache#2368)

Also replaces shadowing of builtin 'dict' in handleAnnotatedValue with 'd',
and uses .get() for safer key access on parsed vertex/edge dicts.

Closes apache#2367
Closes apache#2368
Verify that malformed and truncated agtype strings raise AGTypeError
(or recover gracefully) rather than crashing with AttributeError.
This tests the null-guards added to the ANTLR parser visitor.

Made-with: Cursor

@uesleilima

- visitFloatLiteral: raise AGTypeError on malformed child node instead
  of silently returning a fallback value
- visitObj: add comment documenting that visitPair's validation makes
  the None-guard defensive-only
- handleAnnotatedValue: add comment explaining partial-construction
  behavior on type-check failure
- pyproject.toml: add comment explaining ANTLR4 version range rationale
- Tests: assert AGTypeError (or graceful recovery) for malformed and
  truncated inputs, not just absence of AttributeError

Made-with: Cursor

@uesleilima

- handleAnnotatedValue: default properties to {} when missing from
  parsed dict, preventing __getitem__ crashes on access
- Tests: replace weak assertNotIsInstance with structural type checks
- Fix truncated test docstring to match actual assertion behavior

Made-with: Cursor