-
-
Notifications
You must be signed in to change notification settings - Fork 250
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
Server_default including quote not detected properly #1177
Comments
this happens all in the SQL server dialect at https://github.com/sqlalchemy/alembic/blob/main/alembic/ddl/mssql.py#L227 . the quoting added in the main compare.py is not the issue. for this default, incoming is:
which we trim down to
metadata default is this:
it's the space character, that's about it but if you had a default like this:
SQL Server turns it into
which is nuts. so im going to simplify this and just remove all spaces, parenthesis, double and single quotes from the whole expression, and compare them both on what's left. |
that "substring" example brings out issues with other backends, so i will remove the "add quotes" thing from compare also since that is not helping anyone, the dialects can do this part |
let's not do that since that string is passed to the user defined function |
Mike Bayer has proposed a fix for this issue in the main branch: collapse all chars for mssql defaults, move quoting https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/4448 |
how about we fix this for 1.10 so we can avoid breaking other things in between? (like the _compare_server_default that 3rd party implementation may have added)? I don't think it's a critical bug that cannot wait for 1.10 |
@GeorgeSchneelochVA are you blocked by this? |
@zzzeek Yes, there are several columns with that server default expression in our system so we will need to exclude those tables from migrations for the time being |
I will alter the approach im taking to not have any public behavioral changes |
Thanks for the fix! |
Describe the bug
A column with the server_default
(substring(user_name(),charindex('\',user_name())+(1),len(user_name())))
does not compare properly, causing the migration autogenerate command to think that the server default in the model does not match what is on the database.Expected behavior
A
flask db migrate
command should not create any new migration if the server_default for a column in the model is the string described above, and that column on the database has the same string for its default constraint.To Reproduce
Add a table to SQL Server:
Define the model in SQLAlchemy:
Run flask db migrate with
compare_server_default=True
set in yourMigrate(...)
. There will be a migration generated updating the server_default for that column with exactly the same text as was defined in theserver_default
in the model. The migration should not have been generated since the server default already matches.Error
Versions.
Additional context
I did some investigation and it looks like the value is handled correctly until this line, where single quotes are added to both sides of the string. I'm not sure the intent of the code there, but this server default should be treated as a SQL expression rather than a string.
Have a nice day!
The text was updated successfully, but these errors were encountered: