-
Notifications
You must be signed in to change notification settings - Fork 7
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
Fix modify and save test, add "updated" to modify #416
base: develop
Are you sure you want to change the base?
Conversation
bio-boris
commented
Aug 6, 2021
•
edited
Loading
edited
- Fix modify to update the "updated" timestamp
- Write tests to make sure that the updated timestamp is updated for save and for modify
- Rewrite test_insert_jobs test
Did I miss something in my review or is this a pre-existing issue? |
This is a pre-existing issue that I noticed during #406 (comment) |
del retrieved_job_mongo["_id"] | ||
if "updated" not in original_job_json: | ||
del retrieved_job_json["updated"] | ||
del retrieved_job_mongo["updated"] |
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.
Aren't these two if
s going to be always true or always false?
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
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.
Couple of questions
return super(Job, self).save(*args, **kwargs) | ||
|
||
def modify(self, query=None, **update): | ||
update["updated"] = datetime.utcnow().timestamp() | ||
return super(Job, self).modify(query=None, **update) |
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.
Shouldn't this just pass the query as is, not pass None
?
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.
Assuming I understand this I guess no code uses the query field otherwise tests should've broken
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.
Yea it should pass the query good call
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.
how did the tests pass with this bug?
def test_save_and_modify_updates_timestamp(self): | ||
job = get_example_job(status=Status.created.value) | ||
updated_ts = job.updated | ||
job.save() |
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.
Its seems a bit odd that saving a job updates the timestamp even if there are no changes, is that what you want?
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, updated tracks the last time the job was saved or modified, so seems ok to me. What do you suggest?
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 mean updated to me means that the job was updated, e.g. changed in some way. It doesn't make sense to me for the updated timestamp to change if the job hasn't changed
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.
Alright, so if we make sure to only save jobs with changes, then we should be alright?
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'm not sure if its possible to know if a record has a different value or not when saving unless we reload the record or do two saves?
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.
Alright, so if we make sure to only save jobs with changes, then we should be alright?
I think so, but we should document the behavior clearly
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'm not sure if its possible to know if a record has a different value or not when saving unless we reload the record or do two saves?
You can do a query on the entire record, but that's probably overkill. It'd be nice if Mongo had a feature where a field would only be updated if at least one of a set of provided fields changed