Skip to content

Exclude unique_id from generic repr attrs to avoid duplication - #3776

Merged
tpike3 merged 1 commit into
mesa:mainfrom
dietcoke-17:fix-repr-duplicate-unique-id
Jul 21, 2026
Merged

tpike3 merged 1 commit into
mesa:mainfrom
dietcoke-17:fix-repr-duplicate-unique-id

Conversation

@dietcoke-17

Copy link
Copy Markdown
Contributor

This is a actual bug fix up committed by myself in the PR #3759 which had repr(agent) currently shows unique_id twice "".

Cause
_repr_excluded_fields excludes model and current_action from the generic __dict__ scan, but not unique_id. Since unique_id is also hardcoded into the format string as id={self.unique_id}, it ends up printed twice — once via id=, once via the generic attrs loop.

Fix
One-line change: add unique_id back to _repr_excluded_fields. It's still always shown via the hardcoded id= prefix, so nothing is lost ,it just stops leaking into the generic scan as well.

@github-actions

Copy link
Copy Markdown

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -3.7% [-4.5%, -2.9%] 🟢 -3.9% [-4.5%, -3.3%]
BoltzmannWealth large 🟢 -4.4% [-5.0%, -3.7%] 🟢 -9.8% [-11.4%, -8.2%]
Schelling small 🔵 +0.2% [-1.0%, +1.3%] 🔵 +0.8% [-0.1%, +1.7%]
Schelling large 🔵 +2.4% [+1.7%, +3.2%] 🔴 +10.7% [+9.4%, +12.4%]
WolfSheep small 🔵 +0.1% [-0.5%, +0.7%] 🔵 -0.7% [-4.2%, +2.7%]
WolfSheep large 🔵 -1.7% [-2.3%, -1.0%] 🔵 +1.6% [+0.5%, +2.7%]
SugarscapeG1mt small 🔴 +4.8% [+4.1%, +5.4%] 🔵 +1.3% [-0.1%, +2.9%]
SugarscapeG1mt large 🔵 -1.9% [-3.1%, -0.7%] 🔵 -0.6% [-3.3%, +2.0%]
BoidFlockers small 🔵 -0.6% [-1.2%, -0.1%] 🔵 +2.5% [+2.1%, +2.9%]
BoidFlockers large 🔵 +0.8% [-0.0%, +1.5%] 🔵 +1.8% [+1.6%, +2.0%]

@tpike3 tpike3 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @dietcoke-17

@tpike3
tpike3 merged commit e1e04ba into mesa:main Jul 21, 2026
11 of 12 checks passed
EwoutH pushed a commit that referenced this pull request Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants