Skip to content

Potential default parameter value computation bug in FileStorageContainerCollection #990

@chrisvanrijn

Description

@chrisvanrijn

I stumbled across office365/onedrive/filestorage/container_collection.py (line 16; commit ce11b31) and found that the container_type_id kwarg defaults to a random UUID, but this is done in the function definition, meaning "the expression is evaluated once".

https://docs.python.org/3/reference/compound_stmts.html#function-definitions

Default parameter values are evaluated from left to right when the function definition is executed. This means that the expression is evaluated once, when the function is defined, and that the same “pre-computed” value is used for each call.

I was wondering if this is the desired functionality, or if this might be a bug.

If it is a bug, a potential fix would be to default the parameter to None and then assign a generated UUID inside the body of the function.

def add(self, display_name, container_type_id=None):
  if container_type_id is None:
    container_type_id = uuid.uuid4()

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions