Uh oh!
There was an error while loading. Please reload this page.
Fix datastore: unprefixed ids in client - #1226
Conversation
dhermes
commented
Nov 18, 2015
@mpeg Thanks for bringing this up. I'm trying to understand what this fixes. Can you provide a stacktrace when that |
mpeg
commented
Nov 18, 2015
@dhermes Sure ! It's my first patch so wasn't sure how much detail to give For the dataset Client class, I've got the dataset_id set from an env variable to mpeg-personal (my real dataset name) Here's a REPL and stack trace highlighting the way I encountered this issue: >>>fromgcloudimportdatastore>>>gcd=datastore.Client(namespace='namespace')
>>>gcd.dataset_id'mpeg-personal'>>>existing_key=gcd.get(gcd.key('Test', 5629499534213120)).key>>>existing_key<Key[{'id': 5629499534213120, 'kind': 'Test'}], dataset=e~mpeg-personal>>>>gcd.get(existing_key)
Traceback (mostrecentcalllast):
File"<stdin>", line1, in<module>File"/usr/local/lib/python3.4/dist-packages/gcloud/datastore/client.py", line263, ingetdeferred=deferred)
File"/usr/local/lib/python3.4/dist-packages/gcloud/datastore/client.py", line293, inget_multiraiseValueError('Keys do not match dataset ID')
ValueError: KeysdonotmatchdatasetIDIt all comes down to that string comparison done in the lines my patch changes, which does a comparison ignoring dataset prefixes (as the API will accept an unprefixed dataset_id). The unexpected behaviour for me was that I couldn't store the key that came back and reuse it. |
dhermes
commented
Nov 18, 2015
Really great stacktrace, reproduced on my end! Thanks. Hopefully this will all be mitigated with |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
dhermes
commented
Nov 18, 2015
So the only real issue with this is that we don't have a unit test to make sure the failure doesn't occur again. I can help with that if you like or you can give it a spin yourself? I really appreciate the contribution. |
mpeg
commented
Nov 18, 2015
Sure, I can add the unit test, I'm thinking to the gcloud.datastore.test_client tests, add a test that gets a mock entity with a prefixed dataset_id ? |
dhermes
commented
Nov 18, 2015
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
mpeg
commented
Nov 18, 2015
Added a test, styled after the
|
dhermes
commented
Nov 18, 2015
Really great test thanks! I made some comments but overall it is about perfect (which is not something you expect from a first contrib). |
dhermes
commented
Nov 18, 2015
It just occurred to me that it'd be smart to have another similar test that does fail when the IDs disagree, e.g. |
mpeg
commented
Nov 18, 2015
Yeah I agree with your style comments (sorry about the pep8 failure-to-indent), didn't add a failing test like that since it's largely covered by |
mpeg
commented
Nov 18, 2015
Should all be good now, added the extra test case for Thanks for the help, hopefully first of many Btw, I'm no git wizard but I can rebase my branch to squash the extra commits if you'd prefer, let me know |
dhermes
commented
Nov 18, 2015
LGTM Thanks again! |
Fix datastore: unprefixed ids in client
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
…p/templates/python_library/.kokoro (#1226) Source-Link: https://togithub.com/googleapis/synthtool/commit/bb171351c3946d3c3c32e60f5f18cee8c464ec51 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:f62c53736eccb0c4934a3ea9316e0d57696bb49c1a7c86c726e9bb8a2f87dadf
Source-Link: googleapis/synthtool@f15cc72 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:bc5eed3804aec2f05fad42aacf973821d9500c174015341f721a984a0825b6fd
If datastore id comes back prefixed from the API, and
Client.datastore_idis not prefixed, the'Keys do not match dataset ID'exception is raised.Fixed to use
_dataset_ids_equalfor the comparison instead, which compares ignoring valid prefixes and seems to be the preferred comparison method used elsewhere in the code.