ramitkataria commented on code in PR #57836:
URL: https://github.com/apache/airflow/pull/57836#discussion_r2492810619


##########
airflow-core/src/airflow/migrations/versions/0091_3_2_0_restructure_callback_table.py:
##########
@@ -56,15 +56,16 @@ def upgrade():
     with op.batch_alter_table("callback", schema=None) as batch_op:
         batch_op.add_column(sa.Column("type", sa.String(length=20), 
nullable=False))
         batch_op.add_column(sa.Column("fetch_method", sa.String(length=20), 
nullable=False))
-        batch_op.add_column(sa.Column("data", 
airflow.utils.sqlalchemy.ExtendedJSON(), nullable=True))
+        batch_op.add_column(sa.Column("data", ExtendedJSON(), nullable=False))
         batch_op.add_column(sa.Column("state", sa.String(length=10), 
nullable=True))
         batch_op.add_column(sa.Column("output", sa.Text(), nullable=True))
         batch_op.add_column(sa.Column("trigger_id", sa.Integer(), 
nullable=True))
         batch_op.create_foreign_key(batch_op.f("callback_trigger_id_fkey"), 
"trigger", ["trigger_id"], ["id"])
 
         # Replace INTEGER id with UUID id
         batch_op.drop_column("id")
-        batch_op.add_column(sa.Column("id", UUIDType(binary=False), 
nullable=False, primary_key=True))
+        batch_op.add_column(sa.Column("id", UUIDType(binary=False), 
nullable=False))
+        batch_op.create_primary_key("callback_pkey", ["id"])

Review Comment:
   Thanks for approving! I found the error the original version of this script 
was causing while running unit tests in the other PR:
   ```
   sqlalchemy.exc.ProgrammingError: (psycopg2.errors.InvalidForeignKey) there 
is no unique constraint matching given keys for referenced table "callback"
   
   [SQL: ALTER TABLE deadline ADD CONSTRAINT deadline_callback_id_fkey FOREIGN 
KEY(callback_id) REFERENCES callback (id) ON DELETE CASCADE]
   (Background on this error at: https://sqlalche.me/e/14/f405)
   ```
   This happens with all DB unit tests even in postgres because it doesn't seem 
to actually create the primary key constraint. This didn't happen in the PR 
that added this migration script because no other table was referencing the 
callback table using a foreign key. I wonder why the script didn't raise an 
error about invalid arg primary_key if it couldn't handle it. But anyway, it 
should be fixed after this PR



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to