Skip to content

Django 1.11#2206

Merged
sphuber merged 20 commits into
aiidateam:provenance_redesignfrom
ltalirz:django-1.11-merge-provenance-design
Nov 16, 2018
Merged

Django 1.11#2206
sphuber merged 20 commits into
aiidateam:provenance_redesignfrom
ltalirz:django-1.11-merge-provenance-design

Conversation

@ltalirz
Copy link
Copy Markdown
Member

@ltalirz ltalirz commented Nov 15, 2018

  • update django from 1.8.19 to 1.11.16
  • remove django-extensions dependency
  • move to UUIDField of django 1.11 + add migration
    Note: for the moment, I've replaced the uuid fields also in old migrations. One could try to use a CharField(editable=False, blank=True, max_length=36) there to be safe
  • add unique constraints on all uuid fields
  • move get_filter_expr_from_column from django/sqla to interface
  • delete django-specific get_all_parents function (was only used in tests)

 + remove django-extensions
In the django backend, we were using the UUIDField of django-extensions
(the only use of django-extensions in the codebase).
Since django now provides a UUIDField, django-extensions discontinued
it and we have to move as well.

There are a few changes:

 * the old UUIDField had an "auto" keyword which resulted in a uuid
being automatically generated if none was provided at creation.
  In the new UUIDField, this should be the default behavior (?)
 * the old UUIDField had a "version" keyword which allowed to select the
UUID version.
  The new UUIDField instead has a "default" keyword, which allows to
provide a function to set the default value

For reference, this is the code of the old UUIDField in
django-extensions:
https://github.com/django-extensions/django-extensions/blob/cda632d6f5bd7ac7c63e2172789a55cd21dedd7a/django_extensions/db/fields/__init__.py#L371

And this is the new UUIDField in django 1.11:
https://github.com/django/django/blob/c7cc7526d5ee7d38a6ee1af03610f1aba1ea0c78/django/db/models/fields/__init__.py#L2291
    * this has no "auto" keyword (id=None should cause to use the 'default' when saving)
    * https://stackoverflow.com/a/35210896
        * the default is now "uuid.uuid4()"
        * this is the version we use in AiiDA, so we could just remove the "version" arg
(or we could provide our own UUIDField, where we hardcode version 4 (in case django changes their default in the future)
*
aiida/backends/djsite/settings/settings.py contained a setting

  ROOT_URLCONF = 'aiida.backends.djsite.settings.urls'

The problem: The file aiida.backends.djsite.settings.urls did not exist.
django 1.11 tried to import this non-existing file.

Simply removing this variable solved the problem.
since both sqla and django backends now use the 'uuid' column type for
uuids, the get_filter_expr_from_column function becomes identical
for the django and sqla querybuilder, and has been moved to the
querybuilder interface.
UUIDs were used as keys of dictionaries
django: introduce uniqueness constraints on all uuid columns in the DB
convert uuid to string where it tests whether row already present
in the DB.
__getitem__ of django 1.11 queryset was no longer using our iterator
Was used only in one test +
there is a perfectly fine querybuilder-based implementation
@ltalirz ltalirz changed the title Django 1.11 merge provenance design Django 1.11 Nov 15, 2018
@ltalirz
Copy link
Copy Markdown
Member Author

ltalirz commented Nov 15, 2018

It's not too much code to review; happy to make changes where desired

@ltalirz ltalirz requested a review from sphuber November 15, 2018 22:45
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-6.5%) to 62.201% when pulling b54d6c3 on ltalirz:django-1.11-merge-provenance-design into 6b23ad0 on aiidateam:provenance_redesign.

@coveralls
Copy link
Copy Markdown

coveralls commented Nov 15, 2018

Coverage Status

Coverage decreased (-0.07%) to 68.663% when pulling b54d6c3 on ltalirz:django-1.11-merge-provenance-design into 6b23ad0 on aiidateam:provenance_redesign.

Copy link
Copy Markdown
Contributor

@sphuber sphuber left a comment

Choose a reason for hiding this comment

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

Minor comment and a question, but other than that looks good


:returns: An instance of sqlalchemy.sql.elements.BinaryExpression
"""
# Label is used because it is what is returned for the
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this comment is outdated, because it refers to the old DbCalcState table that has been removed. The state is now a regular attribute. This might make the conditional below easier as we can remove Label but I am not sure.

pass

@classmethod
def get_filter_expr_from_column(cls, operator, value, column):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I notice this has SqlAlchemy imports but is moved to the abstract class. Is this intentional? Because of how the querybuilder for django actually also operates on SqlAlchemy in some way?

@sphuber sphuber merged commit 05113f8 into aiidateam:provenance_redesign Nov 16, 2018
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.

3 participants