-
Notifications
You must be signed in to change notification settings - Fork 31
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
Conversation
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.
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) |
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.
Connection, self
unneeded on Python 3.
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.
Ack, done, thanks!
spanner/dbapi/base_connection.py
Outdated
from .utils import get_table_column_schema as get_table_column_schema_impl | ||
|
||
|
||
class BaseConnection(object): |
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.
No need to inherit from object on Python 3.
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.
Ack, done, thanks!
spanner/dbapi/base_connection.py
Outdated
|
||
def _raise_if_already_closed(self): | ||
""" | ||
Raises an exception if attempting to use an already closed connection. |
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.
PEP 257 verb style is "Raise".
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.
Ack, done, thanks!
spanner/dbapi/base_connection.py
Outdated
|
||
def __handle_update_ddl(self, ddl_statements): | ||
""" | ||
Runs the list of Data Definition Language (DDL) statements on the underlying |
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.
Runs - Run
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.
Ack, done, thanks!
spanner/dbapi/base_connection.py
Outdated
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. |
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.
Chop "Note that" (filler words).
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.
Ack, done, thanks!
spanner/dbapi/base_connection.py
Outdated
google.api_core.operation.Operation.result() | ||
""" | ||
self._raise_if_already_closed() | ||
|
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.
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.
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.
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.
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. |
acfe517
to
e36ef2d
Compare
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.
e36ef2d
to
4b72768
Compare
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! |
Refactored common code for Connection present in both:
which makes it easier to add error handling in one place instead
of in 2 places.