-
-
Notifications
You must be signed in to change notification settings - Fork 253
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
postgresql compare_server_default with floats #241
Comments
Changes by Dimitrios Theodorou (@dtheodor):
|
Michael Bayer (@zzzeek) wrote: was about to say, this should really be stated as text("0.0"); when you put "0.0" directly that means the default is the string value "0.0". the docs for server_default state that it will be quoted as a string otherwise. as far as the exception here, not sure. one idea is to catch the exception and emit as a warning, since this can be fixed on the user end. or to do the cast. let's see how the cast works can you send me a PR ? |
Michael Bayer (@zzzeek) wrote: OK, I guess the idea from the PR is that Postgresql is fine with "default" having the quotes, e.g. this:
so in that sense, even though text() is more specific here, this works anyway so might as well not have alembic's tests choke on it. |
Dimitrios Theodorou (@dtheodor) wrote: Yeah, so this example (from real-life code) is bogus (both Since postgres comparisons use db queries, right now they are kind of unique in that they may crash, leaving you with a failed autogenerate with a stack trace. Is this acceptable or should alembic do some catching of exceptions with some logic whether to consider the comparison as failed and/or logging towards the user? |
Changes by Michael Bayer (@zzzeek):
|
Michael Bayer (@zzzeek) wrote: i think its fine, if pg accepts '0.0' for the default but then not in the SQL, we just work around it as we're doing. |
Migrated issue, originally created by Dimitrios Theodorou (@dtheodor)
After updating Alembic from 0.6.2 to the latest I am getting an exception in the
PostgresqlIpml.compare_server_default
. In particular:My DB schema:
My SQL Alchemy model:
The compare_server_default emits this SQL query (on the left is the rendered_inspector_default, on the right the rendered_metadata_default):
which fails with the DataError
ERROR: invalid input syntax for integer: "0.0"
In Postgres, the DEFAULT values
0
,0.0
and'0.0
' are all valid and have identical end-result for a float column.What would the "proper" solution be here, catch the exception and return False in the comparison, or check the column type and cast to float before comparing?
To avoid the error I set the
server_default
to a float value (server_default=text("0.0")
)The text was updated successfully, but these errors were encountered: