Fix: Method Reporter Validation in DataCollector#3002
Merged
Conversation
|
Performance benchmarks:
|
Contributor
Author
|
Hi @quaquel I have resolved the conflicts and accepted both changes. The tests are passing. Could you please re-approve so the pr can be merged? |
quaquel
approved these changes
Dec 31, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a bug in
DataCollector._validate_model_reporter()where method reporters were never validated due to incorrect conditional logic.The Bug
Original Code (lines 166-168 in
datacollection.py)Why This Was Wrong
callable(self.some_method)Truenot callable(reporter)FalseifconditionFalse and ...Method reporters were completely skipped during validation.
The Fix
Key Changes
not callable(reporter)callable(reporter)pass(nothing)reporter()RuntimeErrorwith reporter nameWhy
reporter()Instead ofreporter(model)?Looking at how
collect()calls method reporters (line 341):Bound methods like
self.some_methodalready haveselfbound, so they're called with no arguments.Comparison Table
AttributeErrorRuntimeErrorwith reporter nameTests Added
Added
TestMethodReporterValidationclass totests/test_datacollector.py:test_broken_method_reporter_raises_runtime_errorRuntimeErrorwith reporter nametest_working_method_reporter_succeedstest_method_reporter_exception_is_wrappedtest_mixed_lambda_and_method_reporterstest_method_reporter_called_without_argsreporter()Test Results
Files Changed
mesa/datacollection.pytests/test_datacollector.pyTestMethodReporterValidationclass (5 tests)Backwards Compatibility
✅ All 363 existing tests pass
✅ Working method reporters unaffected
✅ Only broken reporters now fail with clear error message