Skip to content

Commit 04b8f3f

Browse files
committed
Update pydantic syntax to v2
1 parent 042ddab commit 04b8f3f

6 files changed

Lines changed: 17 additions & 15 deletions

File tree

pygeoapi/models/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Francesco Bartoli <xbartolone@gmail.com>
77
#
88
# Copyright (c) 2023 Sander Schaminee
9-
# Copyright (c) 2024 Francesco Bartoli
9+
# Copyright (c) 2025 Francesco Bartoli
1010
#
1111
# Permission is hereby granted, free of charge, to any person
1212
# obtaining a copy of this software and associated documentation
@@ -36,7 +36,7 @@
3636

3737
class APIRules(BaseModel):
3838
""" Pydantic model for API design rules that must be adhered to. """
39-
api_version: str = Field(regex=r'^\d+\.\d+\..+$',
39+
api_version: str = Field(pattern=r'^\d+\.\d+\..+$',
4040
description="Semantic API version number.")
4141
url_prefix: str = Field(
4242
"",
@@ -62,11 +62,11 @@ def create(**rules_config) -> 'APIRules':
6262
""" Returns a new APIRules instance for the current API version
6363
and configured rules. """
6464
obj = {
65-
k: v for k, v in rules_config.items() if k in APIRules.__fields__
65+
k: v for k, v in rules_config.items() if k in APIRules.model_fields
6666
}
6767
# Validation will fail if required `api_version` is missing
6868
# or if `api_version` is not a semantic version number
69-
return APIRules.parse_obj(obj)
69+
return APIRules.model_validate(obj)
7070

7171
@property
7272
def response_headers(self) -> dict:

pygeoapi/models/openapi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Authors: Francesco Bartoli <xbartolone@gmail.com>
66
#
7-
# Copyright (c) 2024 Francesco Bartoli
7+
# Copyright (c) 2025 Francesco Bartoli
88
#
99
# Permission is hereby granted, free of charge, to any person
1010
# obtaining a copy of this software and associated documentation
@@ -40,4 +40,4 @@ class SupportedFormats(Enum):
4040

4141

4242
class OAPIFormat(BaseModel):
43-
__root__: SupportedFormats = SupportedFormats.YAML
43+
root: SupportedFormats = SupportedFormats.YAML

pygeoapi/provider/mvt_tippecanoe.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# =================================================================
22
#
33
# Authors: Joana Simoes <jo@byteroad.net>
4+
# Francesco Bartoli <xbartolone@gmail.com>
45
#
56
# Copyright (c) 2023 Joana Simoes
7+
# Copyright (c) 2025 Francesco Bartoli
68
#
79
# Permission is hereby granted, free of charge, to any person
810
# obtaining a copy of this software and associated documentation
@@ -302,8 +304,8 @@ def get_html_metadata(self, dataset, server_url, layer, tileset,
302304
content = MVTTilesJson(**metadata_json_content)
303305
content.tiles = service_url
304306
content.vector_layers = json.loads(
305-
metadata_json_content["json"])["vector_layers"]
306-
metadata['metadata'] = content.dict()
307+
metadata_json_content["json"])["vector_layers"]
308+
metadata['metadata'] = content.model_dump()
307309
# Some providers may not implement tilejson metadata
308310
metadata['tilejson_url'] = f'{metadata_url}?f=tilejson'
309311
except ProviderConnectionError:
@@ -365,7 +367,7 @@ def get_default_metadata(self, dataset, server_url, layer, tileset,
365367

366368
content.links = links
367369

368-
return content.dict(exclude_none=True)
370+
return content.model_dump(exclude_none=True)
369371

370372
def get_vendor_metadata(self, dataset, server_url, layer, tileset,
371373
title, description, keywords, **kwargs):
@@ -383,8 +385,8 @@ def get_vendor_metadata(self, dataset, server_url, layer, tileset,
383385
content = MVTTilesJson(**metadata_json_content)
384386
content.tiles = service_url
385387
content.vector_layers = json.loads(
386-
metadata_json_content["json"])["vector_layers"]
387-
return content.dict()
388+
metadata_json_content["json"])["vector_layers"]
389+
return content.model_dump()
388390
except ProviderConnectionError:
389391
msg = f'No tiles metadata json available: {self.service_metadata_url}' # noqa
390392
LOGGER.error(msg)

requirements-django.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Django
2-
pydantic<2.0
2+
pydantic>2.0

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ filelock
44
Flask
55
jinja2
66
jsonschema
7-
pydantic<2.0
7+
pydantic>2.0
88
pygeofilter
99
pygeoif
1010
pyproj

tests/test_models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Authors: Francesco Bartoli <xbartolone@gmail.com>
44
# Tom Kralidis: <tomkralidis@gmail.com>
55
#
6-
# Copyright (c) 2024 Francesco Bartoli
6+
# Copyright (c) 2025 Francesco Bartoli
77
# Copyright (c) 2024 Tom Kralidis
88
#
99
# Permission is hereby granted, free of charge, to any person
@@ -43,5 +43,5 @@ class GeospatialDataTypeFactory(ModelFactory[GeospatialDataType]):
4343
def test_provider_base_geospatial_data_type(
4444
geospatial_data_type_factory: GeospatialDataTypeFactory) -> None:
4545
gdt_instance = geospatial_data_type_factory.build()
46-
assert gdt_instance.dict()
46+
assert gdt_instance.model_dump()
4747
assert isinstance(gdt_instance, GeospatialDataType)

0 commit comments

Comments
 (0)