Skip to content

Commit 15446a0

Browse files
Fix various exceptions under Pydantic 1.x (#288)
1 parent c9e6bb8 commit 15446a0

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

circuit_maintenance_parser/output.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,10 @@ def validate_empty_strings(cls, value):
204204
@classmethod
205205
def validate_empty_circuits(cls, value, values):
206206
"""Validate non-cancel notifications have a populated circuit list."""
207-
values = values.data
207+
try:
208+
values = values.data # pydantic 2.x
209+
except AttributeError: # pydantic 1.x
210+
pass
208211
if len(value) < 1 and values["status"] not in (Status.CANCELLED, Status.COMPLETED):
209212
raise ValueError("At least one circuit has to be included in the maintenance")
210213
return value
@@ -213,7 +216,10 @@ def validate_empty_circuits(cls, value, values):
213216
@classmethod
214217
def validate_end_time(cls, end, values):
215218
"""Validate that End time happens after Start time."""
216-
values = values.data
219+
try:
220+
values = values.data # pydantic 2.x
221+
except AttributeError: # pydantic 1.x
222+
pass
217223
if "start" not in values:
218224
raise ValueError("Start time is a mandatory attribute.")
219225
start = values["start"]

circuit_maintenance_parser/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def get_data_types(cls) -> List[str]:
4646
return cls._data_types.get_default()
4747
except AttributeError:
4848
# TODO: This exception handling is required for Pydantic 1.x compatibility. To be removed when the dependency is deprecated.
49-
return cls._data_types
49+
return cls()._data_types
5050

5151
@classmethod
5252
def get_name(cls) -> str:

circuit_maintenance_parser/provider.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def get_default_organizer(cls) -> str:
155155
return cls._default_organizer.get_default() # type: ignore
156156
except AttributeError:
157157
# TODO: This exception handling is required for Pydantic 1.x compatibility. To be removed when the dependency is deprecated.
158-
return cls._default_organizer
158+
return cls()._default_organizer
159159

160160
@classmethod
161161
def get_default_processors(cls) -> List[GenericProcessor]:
@@ -164,7 +164,7 @@ def get_default_processors(cls) -> List[GenericProcessor]:
164164
return cls._processors.get_default() # type: ignore
165165
except AttributeError:
166166
# TODO: This exception handling is required for Pydantic 1.x compatibility. To be removed when the dependency is deprecated.
167-
return cls._processors
167+
return cls()._processors
168168

169169
@classmethod
170170
def get_default_include_filters(cls) -> Dict[str, List[str]]:
@@ -173,7 +173,7 @@ def get_default_include_filters(cls) -> Dict[str, List[str]]:
173173
return cls._include_filter.get_default() # type: ignore
174174
except AttributeError:
175175
# TODO: This exception handling is required for Pydantic 1.x compatibility. To be removed when the dependency is deprecated.
176-
return cls._include_filter
176+
return cls()._include_filter
177177

178178
@classmethod
179179
def get_default_exclude_filters(cls) -> Dict[str, List[str]]:
@@ -182,7 +182,7 @@ def get_default_exclude_filters(cls) -> Dict[str, List[str]]:
182182
return cls._exclude_filter.get_default() # type: ignore
183183
except AttributeError:
184184
# TODO: This exception handling is required for Pydantic 1.x compatibility. To be removed when the dependency is deprecated.
185-
return cls._exclude_filter
185+
return cls()._exclude_filter
186186

187187
@classmethod
188188
def get_extended_data(cls):

0 commit comments

Comments
 (0)