Skip to content
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

Open
wants to merge 37 commits into
base: develop
Choose a base branch
from

Conversation

bio-boris
Copy link
Collaborator

@bio-boris bio-boris commented Aug 6, 2021

  • 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

@bio-boris bio-boris requested a review from MrCreosote August 6, 2021 21:43
@bio-boris bio-boris changed the title Fix modify and save test Fix modify and save test, add "updated" to modify Aug 6, 2021
@bio-boris bio-boris mentioned this pull request Aug 6, 2021
11 tasks
Base automatically changed from multiple_inserts to develop August 6, 2021 21:49
@MrCreosote
Copy link
Member

Did I miss something in my review or is this a pre-existing issue?

@bio-boris
Copy link
Collaborator Author

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"]
Copy link
Member

Choose a reason for hiding this comment

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

Aren't these two ifs going to be always true or always false?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

@bio-boris bio-boris requested a review from MrCreosote August 13, 2021 00:30
Copy link
Member

@MrCreosote MrCreosote left a 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)
Copy link
Member

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?

Copy link
Member

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

Copy link
Collaborator Author

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

Copy link
Member

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()
Copy link
Member

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?

Copy link
Collaborator Author

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?

Copy link
Member

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

Copy link
Collaborator Author

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?

Copy link
Collaborator Author

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?

Copy link
Member

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

Copy link
Member

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

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.

2 participants