Repository navigation
Conversation
|
Performance benchmarks:
|
| # Check if function with arguments | ||
| elif isinstance(reporter, list): | ||
| if ( | ||
| len(reporter) != 2 |
There was a problem hiding this comment.
there is already validation for the reporter list format in _validate_model_reporter earlier in collect, so this additional check might be redundant.
There was a problem hiding this comment.
Validation only runs when self._validated is False (first collect cycle). After that, users can still mutate model_reporters (or load altered state), and without the guard you can still get a raw IndexError. The extra check preserves a clear ValueError contract instead of leaking internal indexing errors.
There was a problem hiding this comment.
My bad, i overlooked that. Thanks for this.
There was a problem hiding this comment.
Self Review
- Fixes a real usability bug - users now get clear
ValueErrorinstead of crypticIndexError - Dual validation (in
_validate_model_reporterandcollect) handles edge case where reporters are mutated after first validation - Tests verify both malformed cases mentioned in the PR
- Error messages are clear and actionable
|
@EwoutH ready for review |
|
Isn’t this just user error? Is the complexity it adds proportional to the improvement in user experience? |
I don’t think this is only user error in the usual sense. The reporter list format is part of the documented API, and malformed input was producing a low-level internal |
Summary
Fixes a
DataCollectorvalidation gap where malformed list-stylemodel_reporters(for example[func]) bypass validation and later crash incollect()withIndexError: list index out of range.Impact: users get an internal low-level exception instead of a clear actionable validation error.
Bug / Issue
Closes #3513
Context:
model_reporterssupports list format:[function, [params...]].[func]passes validation, then fails at collection time when code accessesreporter[1].Expected:
ValueErrordescribing expected format.Actual (before fix):
IndexError: list index out of range raised fromcollect().Implementation
Updated mesa/datacollection.py in two places:
collect(...)reporter[0](*reporter[1]).ValueErrormessage if format is invalid.This ensures malformed list reporters fail with a user-facing validation error instead of an internal
IndexError.Testing
Added regression tests in
tests/test_datacollector.py:test_function_error_missing_params_list[lambda m: ...]raisesValueErrorwith informative message.test_function_error_invalid_params_type[lambda m, x: ..., 1]raisesValueErrorwith informative message.Additional Notes
GSoC contributor checklist
Context & motivation
I was exploring
DataCollectorand testing edge cases around reporter validation when I noticed an inconsistency in how malformedmodel_reporterslists were handled. A clearly invalid format like["not_callable", [1, 2]]already raised a cleanValueError, but another malformed case like[func]slipped through validation and later failed with a low-levelIndexErrorduringcollect(). I wanted to fix this because it felt like a small but important usability bug: users should get a clear validation error that points to what they configured wrong, rather than an internal indexing failure.What I learned
Working on this helped me understand the different reporter shapes supported by
DataCollectorand how validation and collection interact. What was more subtle than I expected was that fixing the obvious bug was only part of the work; I also had to think about exception consistency, test coverage, and whether the validation change might unintentionally narrow accepted input types. That made the review process more interesting, because it was not just about making the error go away, but about making the behavior clearer and safer without changing more than necessary.Learning repo
🔗 My learning repo: https://github.com/falloficarus22/GSoC-learning-space.git
🔗 Relevant model(s): This is a bug fix in
DataCollectorvalidation and does not require a new feature example model.Readiness checks
pytest --cov=mesa tests/)ruff check . --fix)