Skip to content

TaskiqState.copy mutates the source and overwrites the data key #720

Open

Description

@IlyaKhalafi

Taskiq version

Current main at f08a54a

Python version

Python 3.12.15

OS

Linux

What happened?

Calling the inherited copy() method adds a self-referencing data entry to the original state. An existing user entry with that name is overwritten.

from taskiq.state import TaskiqState

state = TaskiqState()
state.value = 1
copied = state.copy()
print(list(state))  # ['value', 'data']
print(state["data"] is state.data)  # True

Expected the original mapping to remain {"value": 1} and the result to have an independent shallow copy of it.

UserDict.copy() temporarily assigns self.data, which TaskiqState routes through its attribute setter into the mapping. Its inherited __copy__() already avoids that setter and copies the backing dictionary directly.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions