Skip to content

Commit 0a03614

Browse files
committed
Update pydantic syntax to v2
1 parent 78218f7 commit 0a03614

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

pygeoapi/models/config.py

+4-4
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

+2-2
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

+7-5
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
@@ -294,8 +296,8 @@ def get_html_metadata(self, dataset, server_url, layer, tileset,
294296
content = MVTTilesJson(**metadata_json_content)
295297
content.tiles = service_url
296298
content.vector_layers = json.loads(
297-
metadata_json_content["json"])["vector_layers"]
298-
metadata['metadata'] = content.dict()
299+
metadata_json_content["json"])["vector_layers"]
300+
metadata['metadata'] = content.model_dump()
299301
# Some providers may not implement tilejson metadata
300302
metadata['tilejson_url'] = f'{metadata_url}?f=tilejson'
301303
except ProviderConnectionError:
@@ -357,7 +359,7 @@ def get_default_metadata(self, dataset, server_url, layer, tileset,
357359

358360
content.links = links
359361

360-
return content.dict(exclude_none=True)
362+
return content.model_dump(exclude_none=True)
361363

362364
def get_vendor_metadata(self, dataset, server_url, layer, tileset,
363365
title, description, keywords, **kwargs):
@@ -375,8 +377,8 @@ def get_vendor_metadata(self, dataset, server_url, layer, tileset,
375377
content = MVTTilesJson(**metadata_json_content)
376378
content.tiles = service_url
377379
content.vector_layers = json.loads(
378-
metadata_json_content["json"])["vector_layers"]
379-
return content.dict()
380+
metadata_json_content["json"])["vector_layers"]
381+
return content.model_dump()
380382
except ProviderConnectionError:
381383
msg = f'No tiles metadata json available: {self.service_metadata_url}' # noqa
382384
LOGGER.error(msg)

requirements-django.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Django
2-
pydantic<2.0
2+
pydantic>2.0

requirements.txt

+1-1
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

+2-2
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)