Fixed #36947 -- Avoided altering column type when only db_comment changes. - #20817
Conversation
c5e6fab to
3ff3091
Compare
blighj
left a comment
There was a problem hiding this comment.
I played around with this PR, code looks good, I confirmed it worked on postgres locally. I haven't tested other dbs, one feels enough to give me confidence it works.
Should there be a regression test with a GeneratedField per the ticket bug?
3ff3091 to
dcf464b
Compare
Hi @blighj! Thanks for the review. I've added a test |
f7cd4fc to
c079371
Compare
There was a problem hiding this comment.
Thanks for working on this @cliffordgama !
I just hit the same bug myself, on PostgreSQL. I added comments to lots of fields, and where tables had related views, the ALTER COLUMN ... TYPE clauses caused errors that needed the views to be rebuilt. I am working around it with custom migrations, but this fix would be much better.
The patch looks generally good to me. I had tested it myself too.
| if connection.features.supports_independent_comment_alteration: | ||
| self.assertIn("COMMENT ON COLUMN", ctx.captured_queries[0]["sql"]) | ||
| else: | ||
| self.assertIn("ALTER TABLE", ctx.captured_queries[0]["sql"]) |
There was a problem hiding this comment.
Can we assert on the second query too?
| self.assertIn("ALTER TABLE", ctx.captured_queries[0]["sql"]) | |
| self.assertIn("ALTER TABLE", ctx.captured_queries[0]["sql"]) | |
| self.assertIn("COMMENT ON COLUMN", ctx.captured_queries[1]["sql"]) |
There was a problem hiding this comment.
The MySQL backend shows a failure for this one because it doesn't provide the same SQL for comments:
django/django/db/backends/mysql/schema.py
Lines 228 to 230 in cccc004
Instead it produces a single ALTER FIELD. So we got an IndexError after applying the suggestion.
| ): | ||
| editor.alter_field(GenFieldModelComment, old_field, new_field, strict=True) | ||
|
|
||
| self.assertEqual(len(ctx), 1) |
There was a problem hiding this comment.
Why not assert on SQL here too?
c079371 to
010c41c
Compare
|
Hey @adamchainz! I'm happy you ran into this bug so I could get an extra set of eyes on this patch 😅 Thanks for the review! |
|
buildbot, test on oracle. |
…nges. Backends that allow altering column comments without altering the column type should set supports_independent_comment_alteration=True. Thanks Alex Fischer for the report. Co-authored-by: Adam Johnson <[email protected]>
010c41c to
404428e
Compare
sarahboyce
left a comment
There was a problem hiding this comment.
Thank you! This looks good to me ⭐
Trac ticket number
ticket-36947
Backends that allow altering column comments without altering the column type should set
supports_independent_comment_alteration=True.Thanks @a-p-f for the report.
AI Assistance Disclosure (REQUIRED)
Checklist
mainbranch.