Skip to content

Commit f986c1f

Browse files
authored
Merge pull request #36 from TaskarCenterAtUW/bugfix-2065
Fixed BUG-2065
2 parents abb220b + 6e38305 commit f986c1f

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change log
22

3+
### 0.2.11
4+
5+
- Fixed [BUG-2065](https://dev.azure.com/TDEI-UW/TDEI/_workitems/edit/2065/)
6+
- Added functionality to catch serialization errors
7+
- Added unit test cases for that
8+
- Added test file `test_serialization_error.zip` to test the serialization error
9+
310
### 0.2.10
411

512
- Added limit the message error when u_id and v_id are missing

src/python_osw_validation/__init__.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,30 @@ def validate(self, max_errors=20) -> ValidationResult:
161161
# Validate OSW external extensions
162162
for file in validator.externalExtensions:
163163
file_path = os.path.join(file)
164+
file_name = os.path.basename(file)
164165
extensionFile = gpd.read_file(file_path)
165166
invalid_geojson = extensionFile[extensionFile.is_valid == False]
166167
is_valid = len(invalid_geojson) == 0
167168
if not is_valid:
168-
self.errors.append(
169-
f"Invalid geometries found in extension file {file}, list of invalid geometries: {invalid_geojson.to_json()}")
169+
try:
170+
# Safely extract invalid _id or fallback to index if _id is missing
171+
invalid_ids = list(set(invalid_geojson.get('_id', invalid_geojson.index)))
172+
num_invalid = len(invalid_ids)
173+
limit = min(num_invalid, 20)
174+
displayed_invalid = ', '.join(map(str, invalid_ids[:limit]))
175+
self.errors.append(
176+
f"Invalid geometries found in extension file `{file_name}`. Showing {limit if num_invalid > 20 else 'all'} of {num_invalid} invalid geometry IDs: {displayed_invalid}"
177+
)
178+
except Exception as e:
179+
self.errors.append(f"Invalid features found in `{file_name}`, but failed to extract IDs: {e}")
180+
181+
# Optional: Test serializability of extension file
182+
try:
183+
for idx, row in extensionFile.drop(columns='geometry').iterrows():
184+
json.dumps(row.to_dict())
185+
except Exception as e:
186+
self.errors.append(f"Extension file `{file_name}` has non-serializable properties: {e}")
187+
break
170188

171189
if self.errors:
172190
return ValidationResult(False, self.errors)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.2.10'
1+
__version__ = '0.2.11'
2.52 KB
Binary file not shown.

tests/unit_tests/test_osw_validation.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def setUp(self):
3030
self.invalid_zones_file = os.path.join(ASSETS_PATH, 'UW.zones.invalid.zip')
3131
self.valid_osw_file = os.path.join(ASSETS_PATH, 'wa.bellevue.zip')
3232
self.invalid_v_id_file = os.path.join(ASSETS_PATH, '4151.zip')
33+
self.serialization_file = os.path.join(ASSETS_PATH, 'test_serialization_error.zip')
3334
self.schema_file_path = SCHEMA_FILE_PATH
3435
self.invalid_schema_file_path = INVALID_SCHEMA_FILE_PATH
3536

@@ -227,6 +228,13 @@ def test_invalid_zones_file(self):
227228
self.assertFalse(result.is_valid)
228229
self.assertIsNotNone(result.errors)
229230

231+
def test_invalid_serialization_file(self):
232+
validation = OSWValidation(zipfile_path=self.serialization_file)
233+
result = validation.validate()
234+
self.assertFalse(result.is_valid)
235+
self.assertIsNotNone(result.errors)
236+
error_message = next((err for err in result.errors if 'non-serializable' in err.lower()), None)
237+
230238
def test_unmatched_ids_limited_to_20(self):
231239
validation = OSWValidation(zipfile_path=self.invalid_v_id_file)
232240
result = validation.validate()

0 commit comments

Comments
 (0)