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: Avoid error by checking for existence before close. #454

Merged
merged 2 commits into from Mar 5, 2021

Conversation

davcamer
Copy link
Contributor

@davcamer davcamer commented Mar 4, 2021

Summary of Changes

Without checking the existence of the _alchemy_extractor attribute, and that
the value is not None, an AttributeError can be raised when close() is called
if the init method didn't complete. Tasks still call close to clean up, so
this code should check if there is anything to clean up first.

Tests

No tests were added. I am not familiar enough with mocking to set up effective tests.

Documentation

No documentation was added.

CheckList

Make sure you have checked all steps below to ensure a timely review.

  • PR title addresses the issue accurately and concisely. Example: "Updates the version of Flask to v1.0.2"
  • PR includes a summary of changes.
  • PR adds unit tests, updates existing unit tests, OR documents why no test additions or modifications are needed.
  • In case of new functionality, my PR adds documentation that describes how to use it.
    • All the public functions and the classes in the PR contain docstrings that explain what it does
  • PR passes make test

…ors.

A common pattern has emerged where database-specific extractors delegate the execution
of queries to a SQLAlchemyExtractor instance. The DB specific extractor has the code
tailored to a DB's metadata table structure. The SQLAlchemyExtractor has the basic
connection lifecycle code.

The pattern involved a few lines of tricky-looking code to handle configs that looks
like it has been copy-pasted from one config to the next. This pulls that out in to
a factory function in the sql_alchemy_extractor module.

Signed-off-by: Dave Cameron <dcameron@digitalocean.com>
Without checking the existence of the _alchemy_extractor attribute, and that
the value is not None, an AttributeError can be raised when close() if called
if the init method didn't complete. Tasks still call close to clean up, so
this code should check if there is anything to clean up first.

Signed-off-by: Dave Cameron <dcameron@digitalocean.com>
@feng-tao
Copy link
Member

feng-tao commented Mar 5, 2021

thanks for making it DRY!

@feng-tao feng-tao merged commit 5cd0dc8 into amundsen-io:master Mar 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants