Skip to content

Don't toggle mongo collection instance variable#433

Merged
bio-boris merged 4 commits intodevelopfrom
dev-mongo_util_collection_fix
Jan 14, 2022
Merged

Don't toggle mongo collection instance variable#433
bio-boris merged 4 commits intodevelopfrom
dev-mongo_util_collection_fix

Conversation

@MrCreosote
Copy link
Copy Markdown
Member

Description of PR purpose/changes

The current MongoUtil implementation has one mongo_collection instance
variable that can be set to either the jobs collection or the logs collection
depending on which method was called last. Methods that don't explicitly
choose the collection themselves will use the collection set by whichever
method was most recently called, which might be the wrong collection.

This commit makes two separate variables and ensures the right
collection is being used for each method. It also deletes a number of
unused methods.

Jira Ticket / Github Issue

  • [n/a] Added the Jira Ticket to the title of the PR e.g. (DATAUP-69 Adds a PR template)

Testing Instructions

  • Details for how to test the PR:
  • Tests pass in Github Actions and locally
  • Changes available by spinning up a local test suite

Dev Checklist:

  • My code follows the guidelines at https://sites.google.com/truss.works/kbasetruss/data-upload-project/development
  • I have performed a self-review of my own code
  • [n/a] I have commented my code, particularly in hard-to-understand areas
  • [n/a] I have made corresponding changes to the documentation
  • [?] My changes generate no new warnings - lots of warnings
  • [n/a] I have added tests that prove my fix is effective or that my feature works - I could technically add a test, but it'd be very weird and wouldn't make a lot of sense IMO
  • New and existing unit tests pass locally with my changes
  • [n/a] Any dependent changes have been merged and published in downstream modules
  • I have run Black and Flake8 on changed Python Code manually or with git precommit (and the Github Actions build passes)

Updating Version and Release Notes (if applicable)

The current MongoUtil implementation has one `mongo_collection` instance
variable that can be set to either the jobs collection or the logs collection
depending on which method was called last. Methods that don't explicitly
choose the collection themselves will use the collection set by whichever
method was most recently called, which might be the wrong collection.

This commit makes two separate variables and ensures the right
collection is being used for each method. It also deletes a number of
unused methods.
@MrCreosote MrCreosote requested a review from bio-boris January 11, 2022 23:09
:return:
"""
self.mongo_collection = mongo_collection
yield self.pymongoc
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've always been pretty confused about this point of this method, since it doesn't really do anything other than return the client. It doesn't actually close the client connection (which it shouldn't, so that's good) and doesn't do any context managing AFAICT. Setting the mongo collection instance variable here is what caused the problem so I decided to just delete the whole thing and simplify.

return job_ids

def get_job_log_pymongo(self, job_id: str = None):

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.

A lot of this is mostly whitespace changes - it'll be easier to read with whitespace off

},
)

def update_jobs_to_queued(
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.

Unused, replaced by the single job method above

inserted = Job.objects.insert(doc_or_docs=jobs_to_insert, load_bulk=False)
return inserted

def insert_one(self, doc):
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.

All these low level DB methods are unused

e, "".join(traceback.format_exception(None, e, e.__traceback__))
)
raise ValueError(error_msg)
job_col = self.pymongoc[self.mongo_database][self._col_logs]
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 method, if run when the old mongo_collection variable was set to the jobs collection, could add log information to the job record

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 also assume it'd fail with some sort of null pointer-ish error if it was called before one of the other methods that set mongo_collection had been called.

@lgtm-com
Copy link
Copy Markdown

lgtm-com Bot commented Jan 11, 2022

This pull request introduces 1 alert when merging 4c75bda into 18408b2 - view on LGTM.com

new alerts:

  • 1 for Unused import

@bio-boris bio-boris merged commit 6faef7b into develop Jan 14, 2022
@bio-boris bio-boris deleted the dev-mongo_util_collection_fix branch January 14, 2022 20:12
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