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

Don't clobber existing values in create_or_update and update functions. #527

Open
llamasoft opened this issue Sep 27, 2019 · 0 comments
Open

Comments

@llamasoft
Copy link
Contributor

I just got bitten by this pretty badly.

The "create_or_update" and "update" functions actually behave more like "create_or_overwrite". This is caused by the methods passing all of the API's parameters, including those it created default values for, the result is that all of the fields get updated regardless if the user specified them or not.

I've created a gist to demonstrate the issue: https://gist.github.com/llamasoft/ab5724feddf1580cde1ac16f5065a98e

I don't think the library should be adding keys to the params dicts unless the user explicitly provided a value for it. For example, this snippet from update_entity could be replaced with:

if metadata is not None and not isinstance(metadata, dict):
    error_msg = 'unsupported metadata argument provided "{arg}" ({arg_type}), required type: dict"'
    raise exceptions.ParamValidationError(error_msg.format(
        arg=metadata,
        arg_type=type(metadata),
    ))
params = {}
if name is not None:
    params["name"] = name
if metadata is not None:
    params["metadata"] = metadata
if policies is not None:
    params["policies"] = policies
if disabled is not None:
    params["disabled"] = disabled
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

1 participant