8000 Remove unnecessary checks on update with etag by andyfangdz · Pull Request #63 · firebase/firebase-admin-python · GitHub
[go: up one dir, main page]

Skip to content

Remove unnecessary checks on update with etag #63 8000

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

Merged
merged 4 commits into from
Aug 21, 2017

Conversation

andyfangdz
Copy link
Contributor
@andyfangdz andyfangdz commented Aug 20, 2017

This PR fixes #62 by removing unnecessary checks in function _update_with_etag.

Why remove the checks instead of updating the docs?

  1. To be more consistent with Java/Node API
  2. It is specified in the docs that transaction is a set() operation, however, the current code checks the value as if it's an update() operation.

Code of set(), notice how it doesn't do this check at all and is using put like transaction()

def set(self, value):
"""Sets the data at this location to the given value.
The value must be JSON-serializable and not None.
Args:
value: JSON-serialable value to be set at this location.
Raises:
ValueError: If the value is None.
TypeError: If the value is not JSON-serializable.
ApiCallError: If an error occurs while communicating with the remote database server.
"""
if value is None:
raise ValueError('Value must not be None.')
self._client.request_oneway('put', self._add_suffix(), json=value, params='print=silent')

Code of update(), instead of using put, it's using patch. The original author might have borrowed the code from here:

def update(self, value):
"""Updates the specified child keys of this Reference to the provided values.
Args:
value: A dictionary containing the child keys to update, and their new values.
Raises:
ValueError: If value is empty or not a dictionary.
ApiCallError: If an error occurs while communicating with the remote database server.
"""
if not value or not isinstance(value, dict):
raise ValueError('Value argument must be a non-empty dictionary.')
if None in value.keys() or None in value.values():
raise ValueError('Dictionary must not contain None keys or values.')
self._client.request_oneway('patch', self._add_suffix(), json=value, params='print=silent')

/cc @alexanderwhatley @hiranya911

@andyfangdz
Copy link
Contributor Author
andyfangdz commented Aug 20, 2017

I noticed that there's already a PR that changes the API in #59. I think #59 fixes this problem, but it makes sense to merge this PR if public API review takes more time because currently there's no way to update a single leaf element.

andyfangdz added a commit to scc-gatech/infra-nebula that referenced this pull request Aug 20, 2017
@hiranya911 hiranya911 self-requested a review August 20, 2017 22:14
@hiranya911 hiranya911 self-assigned this Aug 20, 2017
@hiranya911
Copy link
Contributor

Thanks @andyfangdz. This looks pretty good. Would you be able to provide an integration test for this as well? See integration/test_db.py and the integration testing guide for more information.

Copy link
Contributor
@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@andyfangdz
Copy link
Contributor Author
andyfangdz commented Aug 20, 2017

@hiranya911 Indeed! Here's the integration test. The test passed on my local env. I also took the liberty of bumping a minor version since this change technically does not break anything already working with 2.2.0.

@hiranya911 hiranya911 merged commit 1a937b0 into firebase:master Aug 21, 2017
@hiranya911
Copy link
Contributor

Thanks @andyfangdz for the contribution.

@andyfangdz andyfangdz deleted the patch-1 branch August 21, 2017 17:41
@andyfangdz
Copy link
Contributor Author

@hiranya911 Can you do a release for 2.2.1 on pypi? Thanks!

@hiranya911
Copy link
Contributor

@andyfangdz I was waiting to see if we can get #59 also approved, and do a 2.3.0 release sometime next week. I will do a release next week regardless of the status of #59. Sorry about the delay.

@andyfangdz
Copy link
Contributor Author

@hiranya911 No worries! Thanks for the fast review 😄. Looking forward to #59!

@hiranya911
Copy link
Contributor

This was released today.

@andyfangdz
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transaction API does not match documentation
2 participants
0