question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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 issue

Describe 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:

  1. Use set self/foo['foo'] = 3
  2. Observe that it creates the attribute foo['foo'] = 3 instead of the attribute foo = {'foo': 3}

Original Repro

  1. 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}}
  2. I attempted to change the duration with the following command:set self/buffs['maxHP']['duration'] = 30
  3. Which created the attribute buffs['maxhp']['duration'] = 30.
  4. I then attempted to delete it with the command set self/buffs['maxHP']['duration'] =
  5. 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:closed
  • Created a year ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
Tegiminiscommented, Jul 7, 2022

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.

0reactions
Griatchcommented, Sep 24, 2022

I can’t reproduce this. Unless there’s some new info, I’ll close it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add a key:value pair to dictionary in Python - GeeksforGeeks
This method will create a new key:value pair on a dictionary by assigning a value to that key.
Read more >
Data Structures (Part II): Dictionaries - Python Like You Mean It
Python's dictionary allows you to store key-value pairs, and then pass the dictionary a key to quickly retrieve its corresponding value.
Read more >
Use cases for the 'setdefault' dict method - Stack Overflow
Sometimes you want to make sure that specific keys exist after creating a dict. defaultdict doesn't work in this case, because it only...
Read more >
Give the TKey and TValue a name for Dictionary ... - GitHub
The first idea that comes to my mind is that you could add another attribute to at most one member (per generic argument)...
Read more >
Using dictionaries to store data as key-value pairs
The dictionary stores objects as key-value pairs and can be used to represent complex real-world data.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found