[BUG] using SET to create a dictionary attribute and assign a key:value pair at the same time creates a misnamed attribute
See original GitHub issueDescribe the bug
Using SET to create a dictionary attribute and assign a key:value pair at the same time through switches creates a misnamed attribute. For example, if you were to use set self/foo['foo'] = 3
, it creates an attribute named foo['foo']
with the value 3, rather than the attribute foo = {'foo': 3}
.
This is a problem because if you then try to remove the misnamed attribute with set self/foo['foo'] =
, it errors out as a mismatch, as it is an integer attribute instead of a dictionary. You can only remove it via code or resetting your typeclass.
To Reproduce
Steps to reproduce the behavior:
- Use
set self/foo['foo'] = 3
- Observe that it creates the attribute
foo['foo'] = 3
instead of the attributefoo = {'foo': 3}
Original Repro
- I had the following attribute on myself:
buffs = {'maxHP': {'ref': <class 'content.bufflist.PropertyBuffTest'>, 'pid': 'maxHP', 'start': 1657171549.4178708, 'duration': 0, 'prevtick': None, 'stacks': 1, 'source': succendo}}
- I attempted to change the duration with the following command:
set self/buffs['maxHP']['duration'] = 30
- Which created the attribute
buffs['maxhp']['duration'] = 30
. - I then attempted to delete it with the command
set self/buffs['maxHP']['duration'] =
- Which resulted in the following traceback:
Traceback (most recent call last):
File "c:\muddev\evennia\evennia\commands\cmdhandler.py", line 621, in _run_command
ret = cmd.func()
File "c:\muddev\evennia\evennia\commands\default\building.py", line 1946, in func
result.append(self.rm_attr(obj, attr, category))
File "c:\muddev\evennia\evennia\commands\default\building.py", line 1739, in rm_attr
deep = self.do_nested_lookup(val, *nested_keys[:-1])
File "c:\muddev\evennia\evennia\commands\default\building.py", line 1706, in do_nested_lookup
result = result.__getitem__(key)
AttributeError: 'int' object has no attribute '__getitem__'
Expected behavior
Either an error that informs the player they must create a dictionary through the format set self/foo = {'foo': 3}
, or proper parsing of set command arguments such that set self/foo['foo'] = 3
creates the attribute foo = {'foo': 3}
.
Environment, Evennia version, OS etc
1.0 dev
Issue Analytics
- State:
- Created a year ago
- Comments:9 (9 by maintainers)
Top GitHub Comments
I’m not sure how I ran into this now since using SET and a deliberately malformed attribute name cleans up properly… so I’m stumped. I think it’s worth keeping this bug around to investigate how I hit this traceback though. I’ll keep poking at it.
I can’t reproduce this. Unless there’s some new info, I’ll close it.