Skip to content

google-cloud-datastore no longer works with freezegun #3284

Description

@remcohaszing

As of google-cloud-datastore 1.0.0 it no longer works together with freezegun.

Workaround: downgrade to google-cloud-datastore 0.23.0

  1. OS type and version:

Ubuntu 17.04, but it was also reproduced on 16.04.

  1. Python version and virtual environment information python --version
$ python --version
Python 3.6.0+
  1. google-cloud-python version pip show google-cloud, pip show google-<service> or pip freeze
$ pip list | grep google-cloud
gapic-google-cloud-datastore-v1 0.15.3 google-cloud-core 0.24.0 google-cloud-datastore 1.0.0 google-cloud-storage 1.0.0 proto-google-cloud-datastore-v1 0.90.3
  1. Stacktrace if available
py.test --tb native
Traceback (mostrecentcalllast):
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/google/gax/retry.py", line120, ininnerreturnto_call(*args)
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/google/gax/retry.py", line68, ininnerreturna_func(*updated_args, **kwargs)
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/grpc/_channel.py", line507, in__call__return_end_unary_response_blocking(state, call, False, deadline)
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/grpc/_channel.py", line455, in_end_unary_response_blockingraise_Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_RendezvousofRPCthatterminatedwith (StatusCode.INTERNAL, ReceivedRST_STREAMwitherrorcode2)>Duringhandlingoftheaboveexception, anotherexceptionoccurred:
Traceback (mostrecentcalllast):
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/google/cloud/datastore/_gax.py", line74, in_catch_remap_gax_erroryieldFile"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/google/cloud/datastore/_gax.py", line173, incommitreturnsuper(GAPICDatastoreAPI, self).commit(*args, **kwargs)
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/google/cloud/gapic/datastore/v1/datastore_client.py", line345, incommitreturnself._commit(request, options)
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/google/gax/api_callable.py", line419, ininnerreturnapi_caller(api_call, this_settings, request)
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/google/gax/api_callable.py", line407, inbase_callerreturnapi_call(*args)
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/google/gax/api_callable.py", line368, ininnerreturna_func(*args, **kwargs)
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/google/gax/retry.py", line126, ininner' classified as transient', exception)
google.gax.errors.RetryError: GaxError(Exceptionoccurredinretrymethodthatwasnotclassifiedastransient, causedby<_RendezvousofRPCthatterminatedwith (StatusCode.INTERNAL, ReceivedRST_STREAMwitherrorcode2)>)
Duringhandlingoftheaboveexception, anotherexceptionoccurred:
Traceback (mostrecentcalllast):
File"/home/remco/example/test.py", line16, intest_put_frozenclient.put(entity)
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/google/cloud/datastore/client.py", line384, inputself.put_multi(entities=[entity])
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/google/cloud/datastore/client.py", line411, input_multicurrent.commit()
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/google/cloud/datastore/batch.py", line273, incommitself._commit()
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/google/cloud/datastore/batch.py", line249, in_commitself.project, mode, self._mutations, transaction=self._id)
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/google/cloud/datastore/_gax.py", line173, incommitreturnsuper(GAPICDatastoreAPI, self).commit(*args, **kwargs)
File"/usr/lib/python3.6/contextlib.py", line100, in__exit__self.gen.throw(type, value, traceback)
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/google/cloud/datastore/_gax.py", line82, in_catch_remap_gax_errorsix.reraise(error_class, new_exc, sys.exc_info()[2])
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/six.py", line685, inreraiseraisevalue.with_traceback(tb)
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/google/cloud/datastore/_gax.py", line74, in_catch_remap_gax_erroryieldFile"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/google/cloud/datastore/_gax.py", line173, incommitreturnsuper(GAPICDatastoreAPI, self).commit(*args, **kwargs)
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/google/cloud/gapic/datastore/v1/datastore_client.py", line345, incommitreturnself._commit(request, options)
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/google/gax/api_callable.py", line419, ininnerreturnapi_caller(api_call, this_settings, request)
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/google/gax/api_callable.py", line407, inbase_callerreturnapi_call(*args)
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/google/gax/api_callable.py", line368, ininnerreturna_func(*args, **kwargs)
File"/home/remco/.local/share/virtualenvs/tmp-35dac56d418be2c/lib/python3.6/site-packages/google/gax/retry.py", line126, ininner' classified as transient', exception)
google.cloud.exceptions.InternalServerError: 500ReceivedRST_STREAMwitherrorcode2
  1. Steps to reproduce

Decorate a function using freezegun.freeze_time from freezegun and put a gcloud datastore entity.

  1. Code example
importgoogle.cloud.datastoreimportpytestfromfreezegunimportfreeze_time# Worksdeftest_put():
client=google.cloud.datastore.Client()
entity=google.cloud.datastore.Entity(key=client.key('spam'))
client.put(entity)
# Fails@freeze_time('3216-08-04')deftest_put_frozen():
client=google.cloud.datastore.Client()
entity=google.cloud.datastore.Entity(key=client.key('spam'))
client.put(entity)

The datastore was launched in the background using the following code:

defstart_datastore():
""" Start an in memory gcloud datastore emulator. The datastore and all of its subprocesses are killed when the Python interpreter is shut down. Raises: RuntimeError: If the datastore failed to start. """tmpdir=tempfile.TemporaryDirectory()
atexit.register(partial(tmpdir.cleanup))
command= (
'gcloud',
'beta',
'emulators',
'datastore',
'start',
'--project', os.environ['GOOGLE_CLOUD_PROJECT'],
'--no-store-on-disk',
'--data-dir', tmpdir.name,
'--consistency', '1.0'
)
proc=subprocess.Popen(
command,
stderr=subprocess.PIPE,
preexec_fn=os.setsid)
atexit.register(partial(os.killpg, os.getpgid(proc.pid), signal.SIGTERM))
logs= []
forlineno, lineinenumerate(proc.stderr):
line=line.decode()
logs.append(line)
if'Dev App Server is now running'inline:
returntmpdir# At the time of writing, 22 lines were printed before the# server was up and running. A small buffer is allowed in case# changes are introduced in the logging output.iflineno>40:
breakraiseRuntimeError('Unable to start datastore\n'+''.join(logs))

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions