-
Notifications
You must be signed in to change notification settings - Fork 18
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
Try to handle changes to type definitions #43
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fd399fb
failing test for #26
Changaco d3a7090
fix #26
Changaco a2846e4
add an xfail test for what we can't fix
Changaco 3ebcc6b
add another failing test
Changaco fae67d8
catch type errors and retry parsing after re-fetching the type info
Changaco 6414fe1
Add a little doc in comments
chadwhitacre b55b87d
specify the expected exception type of the xfail test
Changaco 5d49f4d
improve test name and fix column type to match
Changaco 3431d24
Match the method order in the base class
chadwhitacre 0f422eb
Factor out a method to fetch type information
chadwhitacre 363123f
call `CompositeCaster.parse()` instead of duplicating its code
Changaco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
from postgres.cursors import TooFew, TooMany, SimpleDictCursor | ||
from postgres.orm import ReadOnly, Model | ||
from psycopg2 import InterfaceError, ProgrammingError | ||
from pytest import raises | ||
from pytest import mark, raises | ||
|
||
|
||
DATABASE_URL = os.environ['DATABASE_URL'] | ||
|
@@ -334,6 +334,32 @@ def test_unregister_unregisters_multiple(self): | |
self.db.unregister_model(self.MyModel) | ||
assert self.db.model_registry == {} | ||
|
||
def test_add_column_doesnt_break_anything(self): | ||
self.db.run("ALTER TABLE foo ADD COLUMN boo text") | ||
one = self.db.one("SELECT foo.*::foo FROM foo WHERE bar='baz'") | ||
assert one.boo is None | ||
|
||
def test_replace_column_different_type(self): | ||
self.db.run("CREATE TABLE grok (bar int)") | ||
self.db.run("INSERT INTO grok VALUES (0)") | ||
class EmptyModel(Model): pass | ||
self.db.register_model(EmptyModel, 'grok') | ||
# Add a new column then drop the original one | ||
self.db.run("ALTER TABLE grok ADD COLUMN biz text NOT NULL DEFAULT 'x'") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, this is |
||
self.db.run("ALTER TABLE grok DROP COLUMN bar") | ||
# The number of columns hasn't changed but the names and types have | ||
one = self.db.one("SELECT grok.*::grok FROM grok LIMIT 1") | ||
assert one.biz == 'x' | ||
assert not hasattr(one, 'bar') | ||
|
||
@mark.xfail(raises=AttributeError) | ||
def test_replace_column_same_type_different_name(self): | ||
self.db.run("ALTER TABLE foo ADD COLUMN biz text NOT NULL DEFAULT 0") | ||
self.db.run("ALTER TABLE foo DROP COLUMN bar") | ||
one = self.db.one("SELECT foo.*::foo FROM foo LIMIT 1") | ||
assert one.biz == 0 | ||
assert not hasattr(one, 'bar') | ||
|
||
|
||
# cursor_factory | ||
# ============== | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Where did we get this line from, and why do we not call it in the normal course of operation? Why are we doing something in this case that we don't otherwise do? Don't we need to configure the class when it's first instantiated? Why am I not seeing that in our code? Is it in
psycopg2
?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.
Here's
CompositeCaster
onmaster
.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.
I see, we're calling
_from_db
, which is a constructor classmethod, and then we're overwriting all possible attributes on ourself with the corresponding attributes from the new instance.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.
Clarified in 0f422eb.