You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(python-driver): add null-guards in ANTLR parser and relax runtime version pin (#2372)
Fix two related issues in the Python driver's ANTLR4 parsing pipeline:
- 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).
- 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.
- Also replaces shadowing of builtin 'dict' in handleAnnotatedValue with 'd',
and uses .get() for safer key access on parsed vertex/edge dicts.
- Add tests for malformed/truncated agtype input handling.
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.
- 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
- 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
- Use PostgreSQL "$user" placeholder in SET search_path.
- Exercise real escapes and Unicode in special-characters vertex test (json.dumps).
- Add Python 3.9 trove classifier to match requires-python and dependency comment.
- Build vertex agtype with string concat to avoid invalid f-string braces.
- Assert stored description matches parser behavior: JSON escapes remain
literal, UTF-8 decodes normally (ensure_ascii=False on json.dumps).
- Regenerate parser with ANTLR 4.13.2 to silence runtime-version-mismatch warning.
The generated lexer/parser were hardcoded to check for ANTLR runtime
4.11.1, which triggered a noisy 'ANTLR runtime and generated code
versions disagree' warning when installed against a newer runtime like
4.13.2. Regenerating from Agtype.g4 with the 4.13.2 tool aligns the
generated checkVersion() call with the default-installed runtime in
the allowed dependency range and eliminates the warning.
- Bumps the declared floor of antlr4-python3-runtime to 4.13.2 so the
default install path is warning-free.
Made-with: Cursor
0 commit comments