| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
GeometryField subclasses Field directly (single base), so the _FieldMeta metaclass — which only auto-assigns field_type when there are multiple bases — leaves field_type as None. The base to_python_value/to_db_value converters then call isinstance(value, self.field_type), raising TypeError: isinstance() arg 2 must be a type ... on any non-None value. Declare field_type = str and parametrize as Field[str], mirroring the fix applied to TSVectorField in tortoise#2237.
The `instance` parameter is typed `type[Model] | Model`; passing `None` in these unit tests is fine at runtime (GeometryField's converter does not use it) but trips mypy, so annotate the two calls as the codebase does elsewhere.
| Back | FazBrowse Home | New Git URL |
Description
GeometryField (MySQL) subclasses Field directly with a single base:
The _FieldMeta metaclass only auto-assigns field_type when a field has
multiple bases (len(bases) > 1 and bases[0] is Field). A single-base
subclass therefore keeps the class default field_type = None.
The base value converters use it directly:
So any non-None value round-tripping through GeometryField raises:
This trips both to_python_value (reading a geometry back from the DB) and
to_db_value (writing one).
Fix
Declare a concrete field_type and parametrize the generic, exactly as
#2237 did for
TSVectorField:
Tests
Added tests/contrib/mysql/test_geometry_field.py (DB-free) asserting
field_type is str and that to_python_value/to_db_value handle both
None and a concrete "POINT(1 1)" value without raising. Reproduces as a
TypeError before the fix; passes after.
tests/fields/, tests/schema/test_generate_schema.py and the new test all
pass (474 passed, 66 skipped); ruff format --check and ruff check clean.