-
Notifications
You must be signed in to change notification settings - Fork 31
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
SQLAlchemy/DDL: Handle server_default
column schema argument well
#556
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.
Dear Jan,
thanks a stack for submitting this patch. I like that the test methods enumerate different kinds of values / value types the server_default
argument is able to obtain.
Other than a suggestion about reStructuredText syntax, and maybe a slight naming change on the test methods, I think it will be good to go.
With kind regards,
Andreas.
server_default
column schema argument well
'PRIMARY KEY (pk)\n)\n\n'), ()) | ||
|
||
def test_column_server_default_string(self): | ||
class DummyTable(self.Base): |
Check notice
Code scanning / CodeQL
Unused local variable
'PRIMARY KEY (pk)\n)\n\n'), ()) | ||
|
||
def test_column_server_default_func(self): | ||
class DummyTable(self.Base): |
Check notice
Code scanning / CodeQL
Unused local variable
'PRIMARY KEY (pk)\n)\n\n'), ()) | ||
|
||
def test_column_server_default_constant(self): | ||
class DummyTable(self.Base): |
Check notice
Code scanning / CodeQL
Unused local variable
9757321
to
6a32045
Compare
I applied the fixes and squashed the commits. To be honest, I've been using Markdown so much lately I didn't even realize this is rst, thanks for spotting the issue. |
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.
Look good! I've just added a type related suggestion related to a test case.
fake_cursor.execute.assert_called_with( | ||
('\nCREATE TABLE t (\n\t' | ||
'pk STRING NOT NULL, \n\t' | ||
'a TIMESTAMP DEFAULT \'Zaphod\', \n\t' |
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 is a non-working example as CrateDB will complain here that the Zaphod
string literal cannot be converted to timestamp
. Can we use a different example here? E.g. a TEXT DEFAULT 'CrateDB rocks'
or something like that.
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.
Nice catch. Fixed.
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.
Hi again. After invoking CI, it looks like the test case test_column_server_default_string
needs corresponding adjustments to compensate this fix.
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.
Hi, sorry about that, I would have run the tests before pushing, but I was traveling without access to a dev environment.
I'm home now and the tests pass for me, so I think we're good to go.
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.
Dear Jan,
no worries about that hiccup, and welcome back. Now that I've just merged GH-555, it is my turn to apologize for the inconvenience that you may need to rebase your patch now, and most probably also resolve some conflicts around the same spots where @fetzerms made his changes. Please take your time.
If you could also add a changelog item like 7b86801, the patch will be perfect and complete. Thank you so much!
With kind regards,
Andreas.
P.S.: Don't worry about failing GHA tests. Right now, they are only failing because coverage stats can't be uploaded to Codecov on behalf of your account's permissions, because it would need access to this repository's tokens. While it is a public repository which usually does not need any authentication tokens, we established them the other day after Codecov tripped us very often. It is a known issue that it sometimes blocks access from GitHub, and it happens more often on larger test matrix scenarios, where many requests are being submitted from GitHub to Codecov, like this one. Now you know the whole story ;].
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.
Andreas, thank you for your kind words! I rebased and pushed my changes, luckily the conflicts were relatively mild.
6a32045
to
1d9cf51
Compare
# TODO: once supported add default here | ||
|
||
default = self.get_column_default_string(column) | ||
if default is not None: |
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.
Do we intentionally want to intentionally ignore empty values like []
, ""
, {}
. Why is the reason behind not using?
if default is not None: | |
if default: |
Trying to understand, thanks! 😁
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.
@sanchezfdezjavier
Not sure if I correctly understand your questions, any value beside None
will evaluate to True
.
'' is not None => True
[] is not None => True
{} is not None => True
False is not None => True
While using if default:
it would evaluate to False
for all the above examples, see also https://docs.python.org/3/library/stdtypes.html#truth.
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.
Hi Javi,
get_column_default_string()
probably returns a string, so in the case of non-empty strings, your suggestion might also work in this case.
But a) @seut is generally right, and b) explicitly testing against is not None
also feels safer for me, because it does not suffer from any implicit bool-casting flaws.
With kind regards,
Andreas.
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.
Awesome, that makes sense. Thanks for clarifying!
6e098dd
to
1b63dfa
Compare
CrateDB's SQLAlchemy dialect now handles the `server_default` when generating table DDL. Fix #454.
1b63dfa
to
e84aa11
Compare
'PRIMARY KEY (pk)\n)\n\n'), ()) | ||
|
||
def test_column_server_default_string(self): | ||
class DummyTable(self.Base): |
Check notice
Code scanning / CodeQL
Unused local variable
'PRIMARY KEY (pk)\n)\n\n'), ()) | ||
|
||
def test_column_server_default_func(self): | ||
class DummyTable(self.Base): |
Check notice
Code scanning / CodeQL
Unused local variable
Merged. Thank you again, and have a good weekend. |
Summary of the changes / Why this is an improvement
CrateDB's SQLAlchemy dialect now handles the
server_default
when generating table DDL.Fix crate/sqlalchemy-cratedb#106.
Checklist