Skip to content

Instance ID stability#83

Merged
jamalex merged 9 commits intolearningequality:masterfrom
jamalex:instance_id_stability
Jun 10, 2020
Merged

Instance ID stability#83
jamalex merged 9 commits intolearningequality:masterfrom
jamalex:instance_id_stability

Conversation

@jamalex
Copy link
Copy Markdown
Member

@jamalex jamalex commented Jun 9, 2020

Summary

Addresses #79. Instance ID is now calculated as a function purely of the System ID, MAC address, and Device ID. If it wouldn't otherwise have changed, it is left the same, however.

TODO

  • Have tests been written for the new code?
  • Has documentation been written/updated?
  • New dependencies (if any) added to requirements file

Reviewer guidance

If you PR has a significant size, give the reviewer some helpful remarks

Issues addressed

List the issues solved or partly solved by the PR

Documentation

If the PR has documentation, link the file here (either .rst in your repo or if built on Read The Docs)

@jamalex jamalex changed the title Instance id stability Instance ID stability Jun 9, 2020
@jamalex jamalex requested a review from bjester June 9, 2020 03:00
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jun 9, 2020

Codecov Report

Merging #83 into master will decrease coverage by 1.27%.
The diff coverage is 65.27%.

@@            Coverage Diff             @@
##           master      #83      +/-   ##
==========================================
- Coverage   84.73%   83.46%   -1.28%     
==========================================
  Files          30       31       +1     
  Lines        2195     2316     +121     
  Branches      274      297      +23     
==========================================
+ Hits         1860     1933      +73     
- Misses        249      286      +37     
- Partials       86       97      +11     

@@ -7,6 +7,7 @@
from facility_profile.models import Facility
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Can safely ignore this file. It's primarily just black/linting stuff, and a few small test fixes.

Comment thread morango/models/core.py
instance, _ = cls.get_or_create_current_instance()
cls.objects.filter(id=instance.id).update(counter=F("counter") + 1)
instance.refresh_from_db(fields=["counter"])
return instance
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These are the changes that should fix the "more than one InstanceIDModel" issue.

Comment thread morango/models/core.py
system_id = models.CharField(max_length=100, blank=True)

@classmethod
@transaction.atomic
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The changes in the get_or_create_current_instance method, below, implement the behavior described in #79 (leveraging the helper functions in utils.py)

First, it sees whether the current system parameters (calculated using the "old method") match the "current" instance. If they do, we stick with that to minimize unnecessary churn. If not, we use the "new method" to compute a more robust instance ID.

Comment thread morango/models/utils.py
@@ -0,0 +1,197 @@
import hashlib
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This file is where a lot of the real "work" happens, to support calculation of the Instance ID.

@@ -11,6 +11,7 @@
from facility_profile.models import InteractionLog
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I had to update a number of the tests to change the mocking, since we now compute the Instance ID as a function of different things. This file is an example of that (most of the change is from indentation).

@@ -1,29 +1,43 @@
import hashlib
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Many of the changes here are just from running "black". I'll flag the new stuff.

InstanceIDModel.objects.exclude(id=ident).filter(current=True).exists()
)
self.assertTrue(InstanceIDModel.objects.get(id=ident).current)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The two tests below are new, and are designed to ensure that the Instance ID doesn't change when we aren't wanting it to.

Copy link
Copy Markdown
Member

@bjester bjester left a comment

Choose a reason for hiding this comment

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

Only concern would be the frequent usage of # noqa: E722 but it's understandable.

Comment thread morango/models/core.py Outdated
Comment thread morango/models/utils.py
@jamalex jamalex force-pushed the instance_id_stability branch from 27b8b42 to 48bd637 Compare June 10, 2020 06:06
@jamalex jamalex force-pushed the instance_id_stability branch from 48bd637 to 2157db6 Compare June 10, 2020 06:31
@jamalex
Copy link
Copy Markdown
Member Author

jamalex commented Jun 10, 2020

Tests now passing, merging!

@jamalex jamalex merged commit 94acce6 into learningequality:master Jun 10, 2020
@jamalex jamalex deleted the instance_id_stability branch June 10, 2020 16:13
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