Skip to content

Dictionary unpacking not working? #4932

Closed
@lastmjs

Description

@lastmjs

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.

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