-
Notifications
You must be signed in to change notification settings - Fork 10
Fix yaml validator counter issuer #709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix yaml validator counter issuer #709
Conversation
Co-Authored-By: Claude <[email protected]>
…ray indices in error messages Co-Authored-By: Claude <[email protected]>
🔍 Schema Preview DeployedPreview URLs:
Production URLs (unchanged):
|
Co-authored-by: dayantur <[email protected]>
🤖 I've automatically formatted the code in this PR using:
Please pull the latest changes before making further edits. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @dayantur – please take a look and see if these make sense.
Thanks for working on this PR, @dayantur! The GRIDID improvements make error messages much more user-friendly. 🎉 After reviewing the code together with Claude, we identified an edge case in the string replacement approach in The Issue:
Suggested Solution: @classmethod
def _transform_validation_error(cls, error: ValidationError, config_data: dict) -> ValidationError:
"""Transform Pydantic validation errors to use GRIDID instead of array indices."""
# Extract GRIDID mapping from sites
sites = config_data.get("sites", [])
site_gridid_map = {}
for idx, site in enumerate(sites):
if isinstance(site, dict):
gridiv = site.get("gridiv")
if isinstance(gridiv, dict) and "value" in gridiv:
site_gridid_map[idx] = gridiv["value"]
elif gridiv is not None:
site_gridid_map[idx] = gridiv
else:
site_gridid_map[idx] = idx
else:
site_gridid_map[idx] = idx
# Process structured errors (not string manipulation!)
modified_errors = []
for err in error.errors():
err_copy = err.copy()
loc_list = list(err_copy['loc'])
# Replace numeric site index with GRIDID in location tuple
if len(loc_list) >= 2 and loc_list[0] == 'sites' and isinstance(loc_list[1], int):
site_idx = loc_list[1]
if site_idx in site_gridid_map:
loc_list[1] = site_gridid_map[site_idx]
err_copy['loc'] = tuple(loc_list)
modified_errors.append(err_copy)
# Format into readable message
error_lines = [f"{error.error_count()} validation error{'s' if error.error_count() > 1 else ''} for SUEWSConfig"]
for err in modified_errors:
loc_str = '.'.join(str(x) for x in err['loc'])
error_lines.append(loc_str)
error_lines.append(f" {err['msg']} [type={err['type']}, input_value={err['input']}, input_type={type(err['input']).__name__}]")
if 'url' in err:
error_lines.append(f" For further information visit {err['url']}")
error_msg = '\n'.join(error_lines)
raise ValueError(f"SUEWS Configuration Validation Error:\n{error_msg}") Why this works:
Let me know if you'd like me to push this change or if you'd prefer to implement it! Either way, great work on improving the user experience with GRIDID-based error messages. 👏 |
hi @sunt05 :) this looks good - please go ahead with your proposed solution and let me know if you need me to revise it before merging |
Then please implement that and I'll have a look later this afternoon - now need to go to some other meetings :) |
Co-authored-by: dayantur <[email protected]>
🤖 I've automatically formatted the code in this PR using:
Please pull the latest changes before making further edits. |
…ttps://github.com/UMEP-dev/SUEWS into dayantur/validator/fix/yaml-validator-counter-issue
Co-authored-by: dayantur <[email protected]>
🤖 I've automatically formatted the code in this PR using:
Please pull the latest changes before making further edits. |
hi @sunt05 - I have addressed the changes you requested :) and implemented your solution for the buggy GRID ID problem with string replacement. This should now hopefully work as expected. I also added some tests to cover the fixes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done! 🎉
The GRIDID transformation implementation looks excellent. The structured error processing approach correctly handles the edge case where GRIDID values could overlap with array indices, and you've provided comprehensive test coverage.
Key strengths:
- ✅ Proper use of Pydantic's structured error data (avoids string replacement collisions)
- ✅ Consistent GRIDID display across all validation phases (A, B, C)
- ✅ Test coverage for edge cases
- ✅ Graceful fallback to array indices when GRIDID unavailable
This will significantly improve the user experience for multi-site configurations. Approved!
The CI is failing on the two new GRIDID collision tests. The issue is that both test sites have invalid data (
Both sites will generate
The test assertion Fix: Make only ONE site invalid in each test: def _create_invalid_config(self, gridid_values, invalid_site_index=0):
"""Create config with specified GRIDID values, only one site invalid."""
sites = []
for i, gid in enumerate(gridid_values):
lat_value = None if i == invalid_site_index else 51.5 # Only first site invalid
sites.append({'gridiv': gid, 'properties': {'lat': lat_value, 'lng': 0.0}})
# ... rest of method This ensures only site 0 (GRIDID=1 or 10) generates an error, so |
Updating my review status: I need to change my approval to request changes due to the failing tests. @dayantur - Please update the test to make only one site invalid per test case. This will ensure the GRIDID appears exactly once in the error message, which is what the test expects. Once the tests pass, I'll re-approve! |
- Only make first site invalid to avoid multiple error instances - Update assertions to check that only invalid site appears in errors - Verify array indices are properly transformed to GRIDIDs
I've fixed the failing tests! ✅ The issue was with the test logic - the tests were creating multiple invalid sites but expecting each GRIDID to appear only once in error messages. Changes made:
All tests now pass locally. The CI should pass once the builds run. |
Thanks @sunt05 :) I already logged off when you spotted the failing test! Fingers crossed now for the fixed version |
This PR addresses issue #703 by changing terminal outputs and report messages to be in line with grid-id number rather than the internal site index counter.
Main changes
gridiv
for sites array instead of numeric indexgridiv
for site identification instead of numeric index in report messagesgridiv
for site identification instead of numeric index in report messagesgridiv
number in terminal outputs from Pydantic model error messages