-
-
Notifications
You must be signed in to change notification settings - Fork 352
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
Infer column type two #135
Conversation
The merge with master was too hairy, started a new branch.
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.
Approving to unblock, please make requested changes before merging. Looks good overall!
|
||
|
||
@pytest.fixture | ||
def temporary_testing_schema(engine_with_types): |
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.
You're using this fixture in multiple files, I recommend putting it in conftest.py
in the root of this folder so that you can reuse 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.
Same with other reused fixtures.
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.
My reasoning was that these fixtures use code from mathesar that is tested by test files with no access to these fixtures. (This makes sure we're not using fixtures in a way that invalidates the tests that test the code they use. Do you know of a way to separate those out (or make it difficult/obvious when you shouldn't use a given fixture for testing? In particular, I'd want to find some way to guarantee that these fixtures won't be used for testing the db/types/install.py
file at some point in the future.
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.
You could organize the files differently so that any tests that can use these fixtures are in a single directory with the appropriate conftest.py
and files that shouldn't use these fixtures are in a different directory.
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.
that seems like the obvious solution to me but I might be missing something.
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.
We could also put these fixtures in a non-default file (i.e., not a conftest.py
file), then import it. It's kind of non-standard, but I think it'd be less confusing than partially mirroring the directory structure of the tested files with the structure of the test files.
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.
Actually, I think that's probably my favorite solution.
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.
For that kind of reorganization, I think it'd merit its own PR to document what was done and why with the restructuring. @kgodey, what do you think?
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.
@mathemancer I think importing a non-standard file makes sense, and doing it in a separate PR also makes sense. I was originally thinking you'd reorganize the real files as well, but I like your solution too.
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'll double-check that the organization of the real files makes sense and adjust accordingly.
db/tests/types/test_inference.py
Outdated
TEST_TABLE = "test_table" | ||
TEST_COLUMN = "test_column" | ||
metadata = MetaData(bind=engine) | ||
print(value_list) |
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.
Is this a debug print?
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.
oops, good eye.
) | ||
break | ||
except Exception: | ||
logger.info( |
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.
Shouldn't this be logger.error
?
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.
This exception is an expected part of the control flow (it's how we know when a given type is inappropriate for a given column). I think info
is reasonable for that. I do think I should remove the spot where I set the log level to INFO
in this file, though (it should be set by the importer if they want a non-default level). What do you think?
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.
Can you catch the specific exception you're expecting and add a comment explaining it's the expected flow?
I agree re: removing log level in the file.
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.
Unfortunately, there's a bunch of different exceptions based on which type was casting to which other. I can try to figure out if they're sub-classes of something appropriate (I think python will catch the parent class in that case, I'll have to check)
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.
Okay, we'll use sqlalchemy.exc.DatabaseError
. It's not super-precise, but it at least restricts to "you asked to do something and the DB said no".
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.
Looks good, thanks!
) | ||
break | ||
except Exception: | ||
logger.info( |
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.
Looks good, thanks!
Fixes #92
This adds a function to infer the type of the column by attempting to alter the column to various types in a logical order.
Technical details
This has the side effect of losing data in the case where the column is altered to a type via some non-injective mapping. For example, altering the strings
'0123'
and'123'
to a numeric will result in the value123
in both cases. It's not possible to recover the original strings from the resulting value.We'll add mechanisms to recover the original version of an altered column in future PRs.
Checklist
Update index.md
).master
branch of the repositoryvisible errors.
Developer Certificate of Origin
Developer Certificate of Origin