-
Notifications
You must be signed in to change notification settings - Fork 11
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 Django 1.8(.3) #167
Conversation
This commit contains changes required while upgrading the Django from v1.6.7 - v1.8.3 - Deprecated @transaction.commit_manually usage in common/maindb.py - Changed as suggested in: https://realpython.com/blog/python/transaction-management-with-django-1-6/ - Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is prohibited; - Added fields = "__all__" to all the ModelForms - Changed the referncing style in many files (forms.py, admin.py, maindb.py, views.py) to be consistent and complying with the recommended format of version>1.6 - The server runs without any errors, but with some "loud warnings" which pertain to projected deprecated modules in v1.9 Conflicts: website/html/forms.py website/html/views.py
Few changes in models and corresponding migrations Conflicts: website/control/admin.py website/control/models.py website/html/forms.py website/html/templates/accounts/accounts_base.html website/html/templates/accounts/experimentregistration.html website/html/templates/accounts/register.html website/html/templates/common/geni_base.html website/html/views.py website/populate_sensibility.py
Passing mimetype to HttpResponse is deprecated and removed in Django 1.7 per django/django@8eadbc5” content_type should be used instead. Changed two HttpResponse calls here.
- Had to switch back to from clearinghouse.x.y import z rather than from x.y import z. Was like that in master branch of main repo; not sure why it was changed (probably a good reason…?), but doesn’t work for me otherwise.
Fixes #152 |
Cleaned up :P |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed all the code changes. Most of it looks good, but I did suggest a couple of minor modifications and clarifications.
Also I installed Clearinghouse in a Ubuntu machine, clicked through the pages, created a user and downloaded an installer, which all seemed to work, without any suspicious log messages.
I did find a bunch of RemovedInDjango19Warning and RemovedInDjango110Warning though, but I guess we can address these in a new PR.
django.db.transaction.enter_transaction_management() | ||
# Beginning of part of fix for Issue #152 | ||
# 1. Remove enter_transaction_management() line (Functionality removed in | ||
# Django 1.8. Expecting autocommit to work in its absence.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should either actually remove the line or say "Commented out".
enter_transaction_management
indeed does not exist in 1.8, and it was already labeled "Deprecated private API" in 1.6, that's probably why the removal isn't even mentioned in the Deprecation Timeline.
Autocommit (default), which "wraps every SQL query in its own transaction", should do the trick as mentioned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in c849e07.
|
||
# If we are in a django version that has django.setup() (1.7+?), run django.setup() | ||
# This is needed for django compatibility. | ||
# So that it works, undo the repy custom patching of the type builtin so that django can use it. We'll turn it back on after. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does django.setup()
have to import safe.py
? I suppose it's not just in order to first override type
and then use the backed up original type
. Maybe the comments could be more specific?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, let's not worry about Django versions that don't have django.setup
. Backwards compatibility is of no use here. Once we require Django 1.8 to be installed for a CH, we cease supporting previous versions. (Side note: The point is more difficult to make for the Seattle "client" software where we have a large installed base with an old version of Python.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed (but not thoroughly checked for relevance) in e85f995.
django.setup() | ||
__builtins__.type = temp_type | ||
# end of part of fix for Issue #152 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DRY! Maybe we could put this mysterious piece of code into a function. See comment above for why it's mysterious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above --- we require a suitable Django version with django.setup
from now on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also addressed in e85f995, see above for caveats.
@@ -159,7 +159,7 @@ def init_maindb(): | |||
|
|||
|
|||
|
|||
@transaction.commit_manually | |||
# @transaction.commit_manually |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line can be removed. The commit_manually decorator was removed in Django 1.8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in e85f995 which also fixed the module-level docstring.
geniuser.set_password(password) | ||
geniuser.save() | ||
|
||
regenerate_api_key(geniuser) | ||
|
||
except: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw. our code-guidelines urge to use Class-based exceptions (I know this is not part of this PR).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Well-spotted! I've added issue #175 for this.)
@@ -868,7 +873,9 @@ def priv_key(request): | |||
except LoggedInButFailedGetGeniUserError: | |||
return _show_failed_get_geniuser_page(request) | |||
|
|||
response = HttpResponse(user.user_privkey, mimetype='text/plain') | |||
# Fixed for Issue #152, compatibility with Django 1.8+ requires shift from | |||
# mime_type argument to content_type argument. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response = HttpResponse(user.user_privkey, mimetype='text/plain') | ||
# Fixed for Issue #152, compatibility with Django 1.8+ requires shift from | ||
# mime_type argument to content_type argument. | ||
response = HttpResponse(user.user_privkey, content_type='text/plain') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d428418 removes that comment, again I think it should be in the commit message.
@@ -885,7 +892,9 @@ def pub_key(request): | |||
except LoggedInButFailedGetGeniUserError: | |||
return _show_failed_get_geniuser_page(request) | |||
|
|||
response = HttpResponse(user.user_pubkey, mimetype='text/plain') | |||
# Fixed for Issue #152, compatibility with Django 1.8+ requires shift from | |||
# mime_type argument to content_type argument. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True too too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d428418 again, comment --> commit message again.
|
||
# We have our maindb model defined here, so it must be listed. | ||
'clearinghouse.website.control', | ||
# 'clearinghouse.website.control.models', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it must be listed here, why is it commented out?
@@ -215,7 +215,7 @@ | |||
#'social_auth.backends.browserid.BrowserIDBackend', | |||
#'social_auth.backends.contrib.live.LiveBackend', | |||
# Django default this is always needed and must always be last. | |||
'django.contrib.auth.backends.ModelBackend', | |||
'django.contrib.auth.backends.ModelBackend', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two trailing spaces instead of one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 1695579, but there's much more to do.
# connection_created only exists with django >= 1.1 | ||
import django.db.backends.signals | ||
django.db.backends.signals.connection_created.connect(_prepare_newly_created_db_connection) | ||
if django.VERSION >= (1.1): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aaaaalbert pointed out that we can safely get rid of this version check. If someone uses django <= 1.1 we really can't help. Apart from this line I didn't spot any other exaggerated compatibility legacy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in a0b117a.
@lukpueh points out the this call is mentioned as a "Deprecated private API" in the Django 1.7 docs, https://docs.djangoproject.com/en/1.7/_modules/django/db/transaction/Django 1.8 Also, django/django@0f95608 removes the call from the Django codebase. Django’s default behavior is to run in autocommit mode now, see https://docs.djangoproject.com/en/dev/topics/db/transactions/
See the docstring of the `run_django_setup_using_python_type` function for motivation and details.
I'm working to address @lukpueh's comments now. |
Quoting https://docs.djangoproject.com/en/dev/releases/1.6/#deprecated-features-1-6 "Transaction management was completely overhauled in Django 1.6, and the current APIs are deprecated:", going on to list the above decorator.
There doesn't seem to be a need to restore Python's `type` as done in e85f995 .
Also fix indentation.
It related to `gen_edit_user_form` and read "change default field_list from None to '__all__' for Django 1.8 compatibility".
The fix commented relates to Django 1.7's removing of `mime_type` (in favor of `content_type`) in `HttpResponse`. Particularly, the deprecation docs at https://docs.djangoproject.com/en/dev/internals/deprecation/#deprecation-removed-in-1-7 state that "The mimetype argument to the __init__ methods of HttpResponse, SimpleTemplateResponse, and TemplateResponse, will be removed. content_type should be used instead. This also applies to the render_to_response() shortcut and the sitemap views, index() and sitemap()."
@aaaaalbert addressed the requested changes and more:
** I think the type override magic deserves a separate ticket Everything seems to work like before @aaaaalbert's latest changes. (I re-did the same tests and log greping as above) |
Currently, SeattleTestbed/clearinghouse:master runs on Django version 1.6, and does not support Django 1.7 or later. The changes here allow us to run on Django versions through at least Django 1.8.3 (likely through 1.8.x).
See Django deprecation/removal timeline for some of the changes that affected our codebase. In particular, I dealt with:
Some changes were made by user Kaushik1091, and some by me.
Testing:
The Clearinghouse installation procedure is here. While it is updated, Django 1.7+-exclusive instructions are not noted there (In particular, instead of manage.py syncdb, you should employ make manage.py makemigrations followed by manage.py migrate).
Existing code in the pull request has been tested by me on an Ubuntu VM running Django 1.8.3 (also a bit on 1.7 and 1.6.3, though less thoroughly). The clearinghouse website appears to function fully. I've created users, downloaded keys, downloaded donator installers and installed them, seen the donations be registered and carved up by the clearinghouse, requested vessels, and received them. More testing is merited, but it seems to be functional to my eyes.
At present, some of the comments are a bit sloppy or lacking.