ouhft / COPE

Project Repository for Work Package 4 of the COPE Transplant Trial
https://cope.nds.ox.ac.uk
1 stars 0 forks source link

Library Updates - Django 2.0 fixes #316

Closed marshalc closed 6 years ago

marshalc commented 6 years ago

There's the usual range of library updates due, but significantly is the Django 2.0 release which is already on it's .1 update. This introduces some breaking changes - most significantly related to the URL module and defaults. This issue is a place holder to address the things that come up.

We start with (after the updates have been installed) a run of manage.py check which fails with: ImportError: No module named 'django.core.urlresolvers'

marshalc commented 6 years ago

After doing a replace of all the wrong Imports, we now chase... TypeError: __init__() missing 1 required positional argument: 'on_delete' from File "/Users/carl/Projects/py3_cope/cope_repo/wp4/staff/models.py", line 60, in Person

marshalc commented 6 years ago

This one is a new requirement in Django 2 that means all ForeignKey fields need an on_delete property set for them. Working through all the models that use Foreign Keys to update.

marshalc commented 6 years ago

By and large, because we don't delete data from this database (keep the records, mark inactive, etc), we shouldn't have any causes for cascading deletes to occur, in which case most fields can be marked with PROTECT so that errors are raised if an object with things referencing it are attempting to be removed.

marshalc commented 6 years ago

Don't forget this affects OneToOneField as well as the usual ForeignKey.

After that we're looking at django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.

marshalc commented 6 years ago

pm check now returns:

DEBUG: Loading settings from development
SystemCheckError: System check identified some issues:

ERRORS:
?: debug_toolbar.middleware.DebugToolbarMiddleware is missing from MIDDLEWARE.
        HINT: Add debug_toolbar.middleware.DebugToolbarMiddleware to MIDDLEWARE.

System check identified 1 issue (0 silenced).
marshalc commented 6 years ago

Errors now on running server, with:


Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x10353c2f0>
Traceback (most recent call last):
  File "/Users/carl/Projects/py3_cope/lib/python3.5/site-packages/django/utils/autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "/Users/carl/Projects/py3_cope/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 141, in inner_run
    handler = self.get_handler(*args, **options)
  File "/Users/carl/Projects/py3_cope/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler
    handler = super().get_handler(*args, **options)
  File "/Users/carl/Projects/py3_cope/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 66, in get_handler
    return get_internal_wsgi_application()
  File "/Users/carl/Projects/py3_cope/lib/python3.5/site-packages/django/core/servers/basehttp.py", line 44, in get_internal_wsgi_application
    return import_string(app_path)
  File "/Users/carl/Projects/py3_cope/lib/python3.5/site-packages/django/utils/module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "/Users/carl/Projects/py3_cope/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/Users/carl/Projects/py3_cope/cope_repo/config/wsgi.py", line 18, in <module>
    application = get_wsgi_application()
  File "/Users/carl/Projects/py3_cope/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
    return WSGIHandler()
  File "/Users/carl/Projects/py3_cope/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 140, in __init__
    self.load_middleware()
  File "/Users/carl/Projects/py3_cope/lib/python3.5/site-packages/django/core/handlers/base.py", line 39, in load_middleware
    mw_instance = middleware(handler)
TypeError: __init__() takes 1 positional argument but 2 were given

Suspect this is actually due to changes with the Middleware libraries from 1.10 that are now being made obvious by 2.0 - so looking at my own custom middleware ('config.middleware.activate_timezone.TimezoneMiddleware') as this is the most likely one at fault...

marshalc commented 6 years ago

It was, and the custom middleware is now updated and appears to be working. Runserver is now operational, and a quick test through the view stuff appears to be working.

marshalc commented 6 years ago

pm test also works at this stage - though given how few tests are in there, I wouldn't say that's a major win.