-
-
Notifications
You must be signed in to change notification settings - Fork 775
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
[#4267] Activity data for old grants #4317
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4317 +/- ##
==========================================
+ Coverage 30.04% 30.34% +0.29%
==========================================
Files 213 213
Lines 17112 17113 +1
Branches 2311 2312 +1
==========================================
+ Hits 5142 5193 +51
+ Misses 11770 11713 -57
- Partials 200 207 +7
Continue to review full report at Codecov.
|
@owocki @thelostone-mc @danlipert please review my work, thanks |
migration LGTM . thanks for doing this @e18r ! |
Hi @danlipert, please don't forget to check this out. Also, if you need anything, don't hesitate. Thank you so much! |
Hey @e18r - this looks nice! Two questions: 1) were you able to test this effectively on your local? If not, a unit test would be nice. 2) Regarding the "deployment" date - since we don't have continuous deployment set up, that date is not accurate. I can probably figure out when the code was deployed exactly, but I'm wondering if you could make this code a bit more resilient such that it wouldn't create duplicate entries even without filtering the objects by the deployment date. |
Hi @danlipert, 1) I was able to test it effectively (although with little data) on my local environment, but if you prefer, I can do the unit test as well. 2) I will make the migration more resilient by preventing duplicates. This can also help in case the migration is mistakenly run twice. |
9d72bc0
to
3b7e42d
Compare
@danlipert I created a way to check if the activity exists before adding it. Check it out in my latest commit. For unique activity types (create grant and delete grant) it checks that there aren't other activities with that type for the current grant. For other activity types, it also checks that they were made by the same person, and at roughly the same time. The deployment date check is still there as an extra safety layer. Regarding the unit test, have you guys established a way of unit testing data migrations in Gitcoin? I did some research, and found this SO question that suggests a way of doing it. However, maybe the simplest way to test it would be to download a subset of the production database and run the migration locally. What do you think would be the best approach? I'm open to doing both. |
@e18r Nice! Appreciate the extra care taken here :) Code is looking nice, if you can add some unit tests I'll add a tip to the bounty. The strategy that I would take to write the tests is to first create some model objects in the database for grants and subscriptions manually that demonstrate the previous state of the app (i.e. no activity data). Then create some grants and subscriptions through the app itself - either call the underlying helper functions or create mock request objects and call the views individually. This will generate activity data, representing the current state of the app. Then do some asserts showing that there are no duplicates, and that each subscription, cancellation, etc. has the appropriate activity data. You could even have some tests that show what edge cases the helper functions are solving (i.e. |
@danlipert I've been working on the unit test. The hard part is getting the migration to run for the test, which is done with something called MigrationExecutor (see link in my previous post), but it has given me plenty of errors. In order to solve them, I had to modify Gitcoin's I'll keep you posted on my progress. Any help appreciated. |
@danlipert After a lot of work, I located the source of the issue as coming from pytest. When I use However, another, more troubling error appears:
In order to go back to a database state in which the migration wasn't applied, django needs to revert the migration, as explained here. However, it doesn't really make sense to write a reversal method by which I delete all the grant-related activities from a certain date in the past, does it? Please consider employing a more ad-hoc test with production data because I reached a hard limit here. |
@danlipert @thelostone-mc @owocki What are your thoughts on this? |
Hey @e18r - I'm not sure I understand - why is Django trying to run a reverse migration? Maybe instead of running the migration directly, you can have the migration call a helper function, and then in your test just call the helper function instead of the migration itself? |
@danlipert I have a few questions:
|
@e16r ah yes, I think the underscores may cause python's importing to fail :/ I'm thinking you can create a file inside the |
@danlipert when I create the file
Django thinks I created a new migration and expects a Migration class inside |
@e18r Ah, my bad - you'll have to put the helper file elsewhere then |
b3008e2
to
37c6f1b
Compare
@danlipert This PR is ready for review and merge:
|
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.
Looking great @octavioamu @thelostone-mc what do y'all think? @e18r can you squash and rebase? Thanks y'all!
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.
lgtm ^_^
2019-06-19: Solved migration conflicts
@danlipert @thelostone-mc @octavioamu I solved migration dependencies, squashed and rebased. The squash dismissed your reviews, I think, so you probably need to approve them again. |
Fixes #4267
A data migration is introduced, which generates grant-related activity data
that happened before grant-related activity was recorded.
The date before which grant-related activity will be generated was set to
2019-04-24 11:53:00 UTC
, which is when PR #3859 was merged.