Thanks to visit codestin.com
Credit goes to github.com

Skip to content

dbapi: refactor common code for Connector into BaseConnection #346

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

Merged
merged 1 commit into from
Mar 16, 2020

Conversation

odeke-em
Copy link
Contributor

@odeke-em odeke-em commented Mar 16, 2020

Refactored common code for Connection present in both:

  • autocommit_off_connection.py
  • autocommit_on_connection.py

which makes it easier to add error handling in one place instead
of in 2 places.

Copy link
Contributor

@timgraham timgraham left a comment

Choose a reason for hiding this comment

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

Please try not to mix large refactorings with bug fixes as it makes it difficult to see the fix when reviewing and when looking at commit history. The attempted fix for #344 here doesn't get the test passing so perhaps you can remove that part of this commit and just merge the refactoring for now.

def __init__(self, db_handle, session, discard_session):
super(Connection, self).__init__(db_handle)
Copy link
Contributor

Choose a reason for hiding this comment

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

Connection, self unneeded on Python 3.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack, done, thanks!

from .utils import get_table_column_schema as get_table_column_schema_impl


class BaseConnection(object):
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to inherit from object on Python 3.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack, done, thanks!


def _raise_if_already_closed(self):
"""
Raises an exception if attempting to use an already closed connection.
Copy link
Contributor

Choose a reason for hiding this comment

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

PEP 257 verb style is "Raise".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack, done, thanks!


def __handle_update_ddl(self, ddl_statements):
"""
Runs the list of Data Definition Language (DDL) statements on the underlying
Copy link
Contributor

Choose a reason for hiding this comment

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

Runs - Run

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack, done, thanks!

def __handle_update_ddl(self, ddl_statements):
"""
Runs the list of Data Definition Language (DDL) statements on the underlying
database. Note that each DDL statement MUST NOT contain a semicolon.
Copy link
Contributor

Choose a reason for hiding this comment

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

Chop "Note that" (filler words).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack, done, thanks!

google.api_core.operation.Operation.result()
"""
self._raise_if_already_closed()

Copy link
Contributor

Choose a reason for hiding this comment

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

The blank line before each return statement (especially in methods that contain only two lines) looks very awkward to me. I know you have your own code style but I don't think other Python developers will follow it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack, I'll remove this one! I'll update such cases wherever I can, thanks for raising it.
Before we ship out this package, I'll go through and remove my style.

@odeke-em
Copy link
Contributor Author

Please try not to mix large refactorings with bug fixes as it makes it difficult to see the fix when reviewing and when looking at commit history.

Indeed! My bad, I was trying to make up for the very long 3+ hour waits for tests to finish running, by combining in one shot.

@odeke-em odeke-em force-pushed the refactor-common-code-for-Connection branch from acfe517 to e36ef2d Compare March 16, 2020 20:56
@odeke-em odeke-em changed the title dbapi: make duplicate table error return DatabaseError + refactor dbapi: refactor common code for Connector into BaseConnection Mar 16, 2020
Refactored common code for Connection present in both:
* autocommit_off_connection.py
* autocommit_on_connection.py

and moved it into base_connection.py
which makes it easier to add functionality and error handling for
the future, in one place instead of in 2 places.
@odeke-em odeke-em force-pushed the refactor-common-code-for-Connection branch from e36ef2d to 4b72768 Compare March 16, 2020 20:59
@odeke-em
Copy link
Contributor Author

I shall merge this refactoring code and then send a proper focused bug fixing PR for the DatabaseError exception. Thank you for the review, Tim!

@odeke-em odeke-em merged commit 4b72768 into master Mar 16, 2020
@odeke-em odeke-em deleted the refactor-common-code-for-Connection branch March 16, 2020 21:18
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