-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Fix/remove orm from alembic migrations #60012
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
Closed
Arunodoy18
wants to merge
8
commits into
apache:main
from
Arunodoy18:fix/remove-orm-from-alembic-migrations
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ae0507d
Improve CLI date argument help text documentation
Arunodoy18 e766de5
Increase external_executor_id column length from 250 to 1000 characters
Arunodoy18 31a4bdf
Fix duplicate HTTP requests on initial DAG page load
Arunodoy18 f948fd5
Make DataprocDeleteClusterOperator idempotent
Arunodoy18 a2c737e
Optimize HITL polling to reduce unnecessary API calls
Arunodoy18 d20d112
Fix next_dagrun being set back in time due to stale run data
Arunodoy18 e971f84
fix(api): Only allow deleting DAG runs in allowed states (queued, suc…
Arunodoy18 3d33d2f
fix(migrations): Remove ORM usage from Alembic migration scripts
Arunodoy18 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,9 +32,7 @@ | |
|
|
||
| import sqlalchemy as sa | ||
| from alembic import context, op | ||
| from sqlalchemy.orm import lazyload | ||
|
|
||
| from airflow.models.trigger import Trigger | ||
| from airflow.serialization.serialized_objects import BaseSerialization | ||
| from airflow.utils.sqlalchemy import ExtendedJSON | ||
|
|
||
|
|
@@ -46,25 +44,14 @@ | |
| airflow_version = "2.9.0" | ||
|
|
||
|
|
||
| def get_session() -> sa.orm.Session: | ||
| conn = op.get_bind() | ||
| sessionmaker = sa.orm.sessionmaker() | ||
| return sessionmaker(bind=conn) | ||
|
|
||
|
|
||
| def upgrade(): | ||
| """Update trigger kwargs type to string and encrypt.""" | ||
| with op.batch_alter_table("trigger") as batch_op: | ||
| batch_op.alter_column("kwargs", type_=sa.Text(), existing_nullable=False) | ||
|
|
||
| if not context.is_offline_mode(): | ||
| session = get_session() | ||
| try: | ||
| for trigger in session.query(Trigger).options(lazyload(Trigger.task_instance)): | ||
| trigger.kwargs = trigger.kwargs | ||
| session.commit() | ||
| finally: | ||
| session.close() | ||
| # Note: The original migration used ORM to trigger encryption, but was effectively a no-op | ||
| # since it just reassigned trigger.kwargs = trigger.kwargs. The encryption happens automatically | ||
| # via the column type change above when using the encrypted column type in the model. | ||
|
|
||
|
|
||
| def downgrade(): | ||
|
|
@@ -78,14 +65,8 @@ def downgrade(): | |
| ------------ | ||
| """) | ||
| ) | ||
| else: | ||
| session = get_session() | ||
| try: | ||
| for trigger in session.query(Trigger).options(lazyload(Trigger.task_instance)): | ||
| trigger.encrypted_kwargs = json.dumps(BaseSerialization.serialize(trigger.kwargs)) | ||
| session.commit() | ||
| finally: | ||
| session.close() | ||
| # Note: The original migration used ORM to attempt serialization, but this is not necessary | ||
| # for the downgrade. The column type change below handles the conversion. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting, did you test this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it was done , I did test this. |
||
|
|
||
| with op.batch_alter_table("trigger") as batch_op: | ||
| batch_op.alter_column( | ||
|
|
||
73 changes: 73 additions & 0 deletions
73
...w-core/src/airflow/migrations/versions/0094_3_2_0_increase_external_executor_id_length.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| """ | ||
| Increase external_executor_id length to 1000. | ||
|
|
||
| Revision ID: f1a2b3c4d5e6 | ||
| Revises: 665854ef0536 | ||
| Create Date: 2025-12-26 00:00:00.000000 | ||
|
|
||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from alembic import op | ||
|
|
||
| from airflow.migrations.db_types import StringID | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "f1a2b3c4d5e6" | ||
| down_revision = "665854ef0536" | ||
| branch_labels = None | ||
| depends_on = None | ||
| airflow_version = "3.2.0" | ||
|
|
||
|
|
||
| def upgrade(): | ||
| """Increase external_executor_id column length from 250 to 1000 chars.""" | ||
| with op.batch_alter_table("task_instance") as batch_op: | ||
| batch_op.alter_column( | ||
| "external_executor_id", | ||
| type_=StringID(length=1000), | ||
| existing_nullable=True, | ||
| ) | ||
|
|
||
| with op.batch_alter_table("task_instance_history") as batch_op: | ||
| batch_op.alter_column( | ||
| "external_executor_id", | ||
| type_=StringID(length=1000), | ||
| existing_nullable=True, | ||
| ) | ||
|
|
||
|
|
||
| def downgrade(): | ||
| """Revert external_executor_id column length from 1000 to 250 chars.""" | ||
| with op.batch_alter_table("task_instance") as batch_op: | ||
| batch_op.alter_column( | ||
| "external_executor_id", | ||
| type_=StringID(length=250), | ||
| existing_nullable=True, | ||
| ) | ||
|
|
||
| with op.batch_alter_table("task_instance_history") as batch_op: | ||
| batch_op.alter_column( | ||
| "external_executor_id", | ||
| type_=StringID(length=250), | ||
| existing_nullable=True, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Seems there's some mix up here with your other PR