Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dictionary unpacking not working? #4932

Open
lastmjs opened this issue Apr 27, 2023 · 3 comments
Open

Dictionary unpacking not working? #4932

lastmjs opened this issue Apr 27, 2023 · 3 comments

Comments

@lastmjs
Copy link

lastmjs commented Apr 27, 2023

We recently updated our project a couple weeks ago to the latest commit on main. The last time we had done this was in December.

This code used to work:

@update
def create_recording(
    audio: blob, name: str, user_id: Principal
) -> CreateRecordingResult:
    user = users.get(user_id)

    if user is None:
        return {"Err": {"UserDoesNotExist": user_id}}

    id = generate_id()
    recording: Recording = {
        "id": id,
        "audio": audio,
        "created_at": ic.time(),
        "name": name,
        "user_id": user_id,
    }

    recordings.insert(recording["id"], recording)

    updated_user: User = {
        **user,
        "recording_ids": [*user["recording_ids"], recording["id"]],
    }

    users.insert(updated_user["id"], updated_user)

    return {"Ok": recording}

In particular:

    updated_user: User = {
        **user,
        "recording_ids": [*user["recording_ids"], recording["id"]],
    }

updated_user was working just fine, the recording_ids property had all of the previous recording_ids and the new one. But now the recording_ids property is empty when this code is executed.

If I change it to:

    updated_user: User = {
        "id": user["id"],
        "created_at": user["created_at"],
        "username": user["username"],
        "recording_ids": [*user["recording_ids"], recording["id"]],
    }

then everything works as expected. It seems there may be a problem with the dictionary unpacking of **user.

@DimitrisJim
Copy link
Member

can you repro this with a self-contained MRE?

@youknowone
Copy link
Member

The basic scenario is tested here: https://github.com/RustPython/RustPython/blob/main/extra_tests/snippets/builtin_dict.py#L287-L289

We need to find what triggers the bug.

@DimitrisJim
Copy link
Member

yup, hence why we need a good example. I can't tell what is misbehaving in Jordan's example since I can't run it.

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

No branches or pull requests

3 participants