|
67 | 67 | DEFAULT_GEOGRAPHY_ALGORITHM = "spherical" |
68 | 68 |
|
69 | 69 | # Regex patterns for parsing geometry and geography type strings |
70 | | -# Matches: geometry, geometry('CRS'), geometry("CRS") |
| 70 | +# Matches: geometry, geometry('CRS'), geometry('crs'), geometry("CRS") |
71 | 71 | GEOMETRY_REGEX = re.compile(r"geometry(?:\(\s*['\"]([^'\"]+)['\"]\s*\))?$") |
72 | | -# Matches: geography, geography('CRS'), geography('CRS', 'algo') |
| 72 | +# Matches: geography, geography('CRS'), geography('crs', 'algo') |
73 | 73 | GEOGRAPHY_REGEX = re.compile(r"geography(?:\(\s*['\"]([^'\"]+)['\"](?:\s*,\s*['\"]([^'\"]+)['\"])?\s*\))?$") |
74 | 74 |
|
75 | 75 |
|
@@ -182,8 +182,10 @@ def handle_primitive_type(cls, v: Any, handler: ValidatorFunctionWrapHandler) -> |
182 | 182 | # Pydantic works mostly around dicts, and there seems to be something |
183 | 183 | # by not serializing into a RootModel, might revisit this. |
184 | 184 | if isinstance(v, str): |
185 | | - # When constructing GeometryType/GeographyType directly with CRS/algorithm values, |
186 | | - # skip the type string parsing to avoid infinite recursion |
| 185 | + # GeometryType/GeographyType inherit this validator, but their root values are |
| 186 | + # a CRS string (or CRS, algorithm tuple). If we try to parse those as type |
| 187 | + # strings here, we'd re-enter this validator (or raise) instead of letting |
| 188 | + # pydantic validate the raw root values. |
187 | 189 | if cls.__name__ == "GeometryType" and not v.startswith("geometry"): |
188 | 190 | return handler(v) |
189 | 191 | if cls.__name__ == "GeographyType" and not v.startswith("geography"): |
|
0 commit comments