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

Updated Python3 Version #69

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Updated Python3 Version #69

wants to merge 8 commits into from

Conversation

koskorya
Copy link

Didn't touch the precommit or tests. This code is also running here. Hopefully we can team up to update the tests and any other things that can be improved!

@koskorya koskorya requested a review from sjaensch March 23, 2020 16:56
Copy link
Contributor

@sjaensch sjaensch left a comment

Choose a reason for hiding this comment

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

Awesome, this is already looking very good!
One issue is the switch of the underlying datastore. I added an inline comment, but the gist is this: are we sure we need to do so or would it be possible to keep using the current datastore with python-ndb?


import pytz
from google.appengine.ext import ndb
from google.cloud import ndb
Copy link
Contributor

Choose a reason for hiding this comment

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

Very neat, I didn't know about this! This ndb library is not mentioned at all in the datastore migration documentation. Apparently it uses Cloud Firestore internally. Have you thought about how we're going to transfer the data? Or would we start with a new, fresh datastore?

Otherwise we could try out python-ndb, which should allow us to access the data we're currently using.

Copy link
Author

Choose a reason for hiding this comment

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

I may be wrong but it appears the python-ndb is the same as google-cloud-ndb. The docs actually show to pip install google-cloud-ndb here.

Also I believe google migrated all legacy datastore db's to use firestore in datastore mode. Shootie was upgraded using the same libraries so we wouldn't need to transfer any data and will still use the same datastore.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great! That's perfect then!


def get_gravatar(self):
"""Creates gravatar URL from email address."""
m = hashlib.md5()
m.update(self.user.email())
m.update((self.username + '@' + config.DOMAIN).encode())
Copy link
Contributor

Choose a reason for hiding this comment

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

You could make email a property, like full_name is already.

Copy link
Author

Choose a reason for hiding this comment

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

good idea, will do.

util/csrf.py Outdated
token = session.get('_csrf_token')
payload = request.form.get('_csrf_token')
# request form of csrf token is returned as a string of a bytestring, slicing to just retrieve the bytestring
# Not sure how else to do this :/
Copy link
Contributor

Choose a reason for hiding this comment

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

That's because it's already set like that:

<input name="_csrf_token" type="hidden" value="b&#39;f6c75f2e3c191a162335e5ad99b8089d&#39;">

This is a bug in the app related to Python 3, we'll need to fix how we set the csrf token.

Copy link
Contributor

Choose a reason for hiding this comment

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

In line 27, we have this code:

session['_csrf_token'] = binascii.hexlify(os.urandom(16))

hexlify returrns a bytestring. The fix is to decode it:

session['_csrf_token'] = binascii.hexlify(os.urandom(16)).decode('ascii')

Copy link
Author

Choose a reason for hiding this comment

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

I wasn't sure if the csrf token needed to be of type bytes. Will fix!

if not users.get_current_user():
return redirect(users.create_login_url(request.url))
username = oidc.user_getfield('email').split('@')[0]
isAdmin = Employee.query(
Copy link
Contributor

Choose a reason for hiding this comment

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

How about we reuse util.auth.is_admin() here?

Copy link
Author

Choose a reason for hiding this comment

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

Completely forgot about that function! Will fix.

@@ -4,7 +4,7 @@
# and then run "tox" from this directory.

[tox]
envlist = py27
envlist = py37
Copy link
Contributor

Choose a reason for hiding this comment

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

Your travis build is failing because it can't find Python 3.7. You'll need to update .travis.yml as well.

@@ -199,5 +199,6 @@ def _send_love(recipient_key, message, sender_key, secret):
if not secret:
logic.event.add_event(
logic.event.LOVESENT,
'/tasks/subscribers/notify',
Copy link
Author

Choose a reason for hiding this comment

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

Accidentally deleted this line before my original PR.

@sjaensch
Copy link
Contributor

I spent some time today looking into what we can do to get the tests to run. The main problem is that NoseGAE is not compatible with Python 3 - both the code itself as well as the fact that it expects and interfaces with the Python 2 App Engine runtime. The project hasn't had any activity for the past three years, we might want to migrate off of it.

@koskorya, could you add me as a contributor to your fork? That way I can collaborate on it, I might have time tomorrow to work on this.

@koskorya
Copy link
Author

added you @sjaensch!

@sjaensch
Copy link
Contributor

My progress today:

  • NoseGAE uses testbed internally, which is not available for the Python 3 environment
  • We could use the Datastore Emulator for integration testing. Getting it to run on travis could be tricky.
  • However, I wasn't able to see if we could even use the Datastore Emulator since everything requires an OpenID login, even when we remove the requires_login decorator.
  • I tried running tests without NoseGAE and ran into cyclic import issues, since models code (e.g. Employee model) imports main to access oidc, which in turn imports almost everything else. I'll continue working on this tomorrow.

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

Successfully merging this pull request may close these issues.

None yet

2 participants