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

support running inside dev_appserver.py #238

Closed
snarfed opened this issue Nov 9, 2019 · 3 comments
Closed

support running inside dev_appserver.py #238

snarfed opened this issue Nov 9, 2019 · 3 comments
Assignees
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. 🚨 This issue needs some love. type: question Request for information or clarification. Not an issue.

Comments

@snarfed
Copy link

snarfed commented Nov 9, 2019

hi all! first off, thank you for porting ndb to python 3. all of us with python 2 standard app engine apps appreciate it!

i'm trying to use it locally inside dev_appserver.py, because reasons, and it doesn't seem to work out of the box, probably because dev_appserver gives it a sanitized environment that doesn't include any DATASTORE_* variables. it always tries to connect to production datastore.googleapis.com, which obviously i don't want.

if i manually modify my client and point it to the emulator after i've created it, with eg client.host = 'localhost:24754'; client.secure = False, it works fine.

any chance you could add dev_appserver support? thanks in advance!

Environment details

google-cloud-ndb 0.2.0
Cloud SDK (gcloud) 270.0.0
Mac OS X 10.14.6
Python 3.6.5

Steps to reproduce

  1. Run dev_appserver.py --support_datastore_emulator ...
  2. In an app, use with ndb.Client().context(): ...
  3. ndb tries to connect to Cloud Datastore via datastore.googleapis.com
@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Nov 9, 2019
@chrisrossi chrisrossi self-assigned this Nov 12, 2019
@chrisrossi chrisrossi added 🚨 This issue needs some love. and removed triage me I really want to be triaged. labels Nov 12, 2019
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. and removed 🚨 This issue needs some love. 🚨 labels Nov 17, 2019
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. and removed 🚨 This issue needs some love. 🚨 labels Nov 27, 2019
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. and removed 🚨 This issue needs some love. 🚨 labels Dec 7, 2019
@chrisrossi
Copy link
Contributor

Hey @snarfed ,

I spent a little time looking at this. Indeed, when using the "--support_datastore_emulator" option with dev_appserver.py, nothing gets injected into the environment to suggest that there is a local datastore emulator running, so I'm not sure how NDB (or any other library) would be able to to detect this condition on its own. Its possible your work around is the best solution at this time. @andrewsg might have some insight into this, or know someone to ask.

It does look like Google is trying to phase out dev_appserver.py. The new standard for local testing seems to just be running a development WSGI server, like Flask, directly. This is how I've done my own local testing. Is there a reason you need to use dev_appserver.py, or can you just run Flask directly in your local environment?

@snarfed
Copy link
Author

snarfed commented Dec 16, 2019

hey, thanks for looking! totally makes sense. i actually expected dev_appserver would have to do something special like propagate the datastore emulator env vars into the app environment. apologies for filing the bug here; i figured you all worked nearby at google to some degree, but maybe that's just some of you, like @dhermes. no worries.

i'm still using dev_appserver because i need the static file handlers in app.yaml to realistically test apps running locally. i do get that dev_appserver is effectively deprecated, though, and that i should find some other middleware to reproduce those static file handlers locally. just one of the many joys of migrating from python 2 standard to python 3.

i'm happy to keep using my workaround for now. thanks for investigating!

@snarfed
Copy link
Author

snarfed commented Mar 27, 2020

for anyone reading this in the future, i'm no longer monkey patching ndb.Client directly, since that stopped working in ndb 1.1.2. instead, i'm injecting environment variables before instantiating it. details in #376 (comment) . thanks again @chrisrossi!

@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Apr 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. 🚨 This issue needs some love. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants