Skip to content

Commit ae0c89c

Browse files
committed
upgrade: solve deprecate warnings of pydantic v2
1 parent 49ddaba commit ae0c89c

34 files changed

Lines changed: 89 additions & 121 deletions

dags/pipelines/notice_batch_processor_pipelines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def notices_batch_distillation_pipeline(notice_ids: List[str], mongodb_client: M
2222
for notice_id in notice_ids:
2323
notice = notice_repository.get(reference=notice_id)
2424
notice.set_distilled_rdf_manifestation(
25-
distilled_rdf_manifestation=notice.rdf_manifestation.copy())
25+
distilled_rdf_manifestation=notice.rdf_manifestation.model_copy())
2626
notices.append(notice)
2727
for cet_uri in CET_URIS:
2828
deduplicate_entities_by_cet_uri(notices=notices, cet_uri=cet_uri)

ted_sws/alignment_oracle/services/limes_configurator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def generate_xml_config_from_limes_config(limes_config_params: LimesConfigParams
2828
:param limes_config_params:
2929
:return:
3030
"""
31-
return TEMPLATES.get_template(LIMES_CONFIG_TEMPLATE).render(limes_config_params.dict())
31+
return TEMPLATES.get_template(LIMES_CONFIG_TEMPLATE).render(limes_config_params.model_dump())
3232

3333

3434
def generate_default_limes_config_params(source_sparql_endpoint: str,

ted_sws/core/model/manifestation.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from enum import Enum
1111
from typing import List, Union, Optional, Dict
1212

13-
from pydantic import Field
13+
from pydantic import Field, ConfigDict
1414

1515
from ted_sws.core.model import PropertyBaseModel
1616
from ted_sws.core.model.validation_report_data import ReportNoticeData
@@ -44,11 +44,10 @@ class Manifestation(PropertyBaseModel):
4444
A manifestation that embodies a FRBR Work/Expression.
4545
"""
4646

47-
class Config:
48-
validate_assignment = True
49-
orm_mode = True
47+
model_config = ConfigDict(validate_assignment=True,
48+
from_attributes=True)
5049

51-
object_data: str = Field(..., allow_mutation=True)
50+
object_data: str = Field(..., frozen=False)
5251

5352
def __str__(self):
5453
STR_LEN = 150 # constant
@@ -226,8 +225,7 @@ class SPARQLQueryResult(PropertyBaseModel):
226225
message: Optional[str] = None
227226
identifier: Optional[str] = None
228227

229-
class Config:
230-
use_enum_values = True
228+
model_config = ConfigDict(use_enum_values=True)
231229

232230

233231
class SPARQLTestSuiteValidationReport(RDFValidationManifestation):

ted_sws/core/model/metadata.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ class Metadata(PropertyBaseModel):
1919
Unified interface for metadata
2020
"""
2121

22-
class Config:
23-
underscore_attrs_are_private = True
2422

2523

2624
class XMLMetadata(Metadata):

ted_sws/core/model/notice.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from functools import total_ordering
2020
from typing import Optional, List, Union
2121

22-
from pydantic import Field, computed_field
22+
from pydantic import Field, computed_field, ConfigDict
2323

2424
from ted_sws.core.model import PropertyBaseModel
2525
from ted_sws.core.model.lazy_object import LazyObjectABC, LazyObjectFieldsLoaderABC
@@ -120,10 +120,8 @@ class WorkExpression(PropertyBaseModel, abc.ABC):
120120
See: https://www.cosmicpython.com/book/chapter_11_external_events.html
121121
"""
122122

123-
class Config:
124-
underscore_attrs_are_private = True
125-
validate_assignment = True
126-
orm_mode = True
123+
model_config = ConfigDict(validate_assignment=True,
124+
from_attributes=True)
127125

128126
created_at: str = datetime.now().replace(microsecond=0).isoformat()
129127
version_number: int = 0
@@ -184,7 +182,7 @@ class Notice(LazyWorkExpression):
184182
185183
"""
186184
_status: NoticeStatus = NoticeStatus.RAW
187-
ted_id: str = Field(..., allow_mutation=False)
185+
ted_id: str = Field(..., frozen=True)
188186
_original_metadata: Optional[TEDMetadata] = None
189187
_xml_manifestation: Optional[XMLManifestation] = None
190188
_normalised_metadata: Optional[NormalisedMetadata] = None

ted_sws/core/model/supra_notice.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from datetime import datetime, date
1111
from typing import List, Optional
1212

13+
from pydantic import ConfigDict
14+
1315
from ted_sws.core.model import PropertyBaseModel
1416
from ted_sws.core.model.manifestation import Manifestation, ValidationSummaryReport
1517

@@ -19,10 +21,8 @@ class SupraNotice(PropertyBaseModel, abc.ABC):
1921
This is an arbitrary aggregate over a list of notices.
2022
"""
2123

22-
class Config:
23-
underscore_attrs_are_private = True
24-
validate_assignment = True
25-
orm_mode = True
24+
model_config = ConfigDict(validate_assignment=True,
25+
from_attributes=True)
2626

2727
created_at: datetime = datetime.now().replace(microsecond=0)
2828

ted_sws/core/model/transform.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111
from enum import Enum
1212
from typing import List, Optional, Union
1313

14-
from pydantic import field_validator
14+
from pydantic import field_validator, ConfigDict
1515

1616
from ted_sws.core.model import PropertyBaseModel
1717

1818

1919
class MappingSuiteComponent(PropertyBaseModel, abc.ABC):
20-
class Config:
21-
validate_assignment = True
20+
model_config = ConfigDict(validate_assignment=True)
2221

2322

2423
class FileResource(MappingSuiteComponent):

ted_sws/data_manager/adapters/manifestation_repository.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def _update_manifestation(self, reference: str, manifestation: Manifestation, up
5959
:return:
6060
"""
6161
if manifestation is not None:
62-
manifestation_dict = manifestation.dict()
62+
manifestation_dict = manifestation.model_dump()
6363
manifestation_dict[AGGREGATE_REFERENCE_ID] = reference
6464
manifestation_dict[MANIFESTATION_TYPE_ID] = self._manifestation_type
6565
reference = self._build_reference(base_reference=reference)

ted_sws/data_manager/adapters/mapping_suite_repository.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def _create_dict_from_mapping_suite(self, mapping_suite: MappingSuite) -> dict:
6464
:param mapping_suite:
6565
:return:
6666
"""
67-
mapping_suite_dict = mapping_suite.dict()
67+
mapping_suite_dict = mapping_suite.model_dump()
6868
mapping_suite_dict[MONGODB_COLLECTION_ID] = mapping_suite.get_mongodb_id()
6969
mapping_suite_dict[MS_CREATED_AT_KEY] = datetime.fromisoformat(mapping_suite_dict[MS_CREATED_AT_KEY])
7070
inject_date_string_fields(data=mapping_suite_dict, date_field_name=MS_CREATED_AT_KEY)
@@ -215,7 +215,7 @@ def _write_package_metadata(self, mapping_suite: MappingSuite):
215215
package_path = self.repository_path / mapping_suite.identifier
216216
package_path.mkdir(parents=True, exist_ok=True)
217217
metadata_path = package_path / MS_METADATA_FILE_NAME
218-
package_metadata = mapping_suite.dict()
218+
package_metadata = mapping_suite.model_dump()
219219
[package_metadata.pop(key, None) for key in
220220
["transformation_rule_set", "shacl_test_suites", "sparql_test_suites"]]
221221
with metadata_path.open("w", encoding="utf-8") as f:

ted_sws/data_manager/adapters/metadata_repository.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _update_metadata(self, reference: str, metadata: Metadata, upsert: bool = Fa
3737
:return:
3838
"""
3939
if metadata is not None:
40-
metadata_dict = metadata.dict()
40+
metadata_dict = metadata.model_dump()
4141
metadata_dict[AGGREGATE_REFERENCE_ID] = reference
4242
metadata_dict[METADATA_TYPE_ID] = self._metadata_type
4343
reference = self._build_reference(base_reference=reference)

0 commit comments

Comments
 (0)