Since workspace_mapping is cached, if the caller of get_workspace_metadata decides to directly modify the return of that function, it will inadvertently be modifying the cache of that call to workspace_mapping.
For this reason, if a function directly returns the response from a cached function, or includes the response from a cached function as part of the return (e.g. a value in a dictionary), a copy of that data should be returned, to prevent mutating the cached response.
I can't think of any harm to making a copy of these values before returning them. When you fix this, if you could include a comment explaining why we're bothering to make the copy, that would be great.
The primary example I found was here: https://github.com/multinet-app/multinet-server/blob/ba7f385e7e5226be28b782fabf612adae579ca49/multinet/db.py#L218-L229
Since
workspace_mapping
is cached, if the caller ofget_workspace_metadata
decides to directly modify the return of that function, it will inadvertently be modifying the cache of that call toworkspace_mapping
.For this reason, if a function directly returns the response from a cached function, or includes the response from a cached function as part of the return (e.g. a value in a dictionary), a copy of that data should be returned, to prevent mutating the cached response.