-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
Fix trigger_kwargs encryption/decryption on db migration #38876
Conversation
Hi @hussein-awala , can you add more information to the commit message, I'm finding it difficult to understand what you worked on. |
I updated the PR description, could you take a look? |
mock_alembic_upgrade.assert_called_once_with(mock.ANY, f"{from_revision}:{to_revision}", sql=True) | ||
|
||
@pytest.mark.skipif( | ||
conf.get_mandatory_value("database", "sql_alchemy_conn").lower().startswith("sqlite"), | ||
reason="Offline migration not supported for SQLite.", |
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.
Why do we now have this?
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.
The tests are not valid for SQLite
, they should be skipped because of
Line 1563 in 1769ed0
raise AirflowException("Offline migration not supported for SQLite.") |
But before
_get_current_revision
was not used if show_sql_only=True
.
I can refactor it if needed to revert the tests
mock_alembic_upgrade.assert_called_once_with(mock.ANY, f"{from_revision}:{to_revision}", sql=True) | ||
|
||
@pytest.mark.skipif( | ||
conf.get_mandatory_value("database", "sql_alchemy_conn").lower().startswith("sqlite"), | ||
reason="Offline migration not supported for SQLite.", |
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.
The tests are not valid for SQLite
, they should be skipped because of
Line 1563 in 1769ed0
raise AirflowException("Offline migration not supported for SQLite.") |
But before
_get_current_revision
was not used if show_sql_only=True
.
I can refactor it if needed to revert the tests
Co-authored-by: Ephraim Anierobi <splendidzigy24@gmail.com>
current_version = _from_revision | ||
trigger_kwargs_encryption_revision = _REVISION_HEADS_MAP["2.9.0"] | ||
if ( | ||
_from_revision != trigger_kwargs_encryption_revision | ||
and _revision_greater(config, trigger_kwargs_encryption_revision, _from_revision) | ||
and _revision_greater(config, current_version, trigger_kwargs_encryption_revision) | ||
): | ||
# _from_revision < trigger_kwargs_encryption_version <= current_version |
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.
I'm a bit confused here. If current_vesrion = _from_revision
, then when will _from_revision < trigger_kwargs_encryption_version <= current_version
happen?
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.
Same here, this comment looks quite wrong here.
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.
Is there confusion between from_revision
I wonder? Not sure which is intended here.
@pytest.mark.skipif( | ||
conf.get_mandatory_value("database", "sql_alchemy_conn").lower().startswith("sqlite"), | ||
reason="Offline migration not supported for SQLite.", | ||
) |
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.
Maybe mark it for supported backend?
@pytest.mark.skipif( | |
conf.get_mandatory_value("database", "sql_alchemy_conn").lower().startswith("sqlite"), | |
reason="Offline migration not supported for SQLite.", | |
) | |
@pytest.mark.backend("postgres", "mysql") |
Should we consider yanking 2.9.0 once 2.9.1 is out with this fix? |
I don't think so. |
Ignoring that the conditional is wrong, I don't follow how this migration approach works for offline migration in the first place. Am I missing functionality somewhere that solves that scenario? |
Just confirmed my suspicions, it doesn't work for offline migrations:
This was all that was spit out for that migration:
|
To me, I’m not sure whether it meets the criteria of critical, but it’s pretty bad. If the user is using helm chart, then it will run the migration pod a lot, and if there are triggers in flight, this could happen and sorta bork the cluster IIUC. |
Currently downgrade also doesn't work when you have triggers - alembic tries to switch the column back to json before decrypting happens. |
I've opened #39246 as an alternative solution to this. |
Closing this as #39246 has been merged. Thanks for kicking off fixing this bug @hussein-awala! |
closes: #38836
This PR updates the trigger kwargs encryption condition to
from_revision < trigger_kwargs_encryption_version <= current_version
and the trigger kwargs decryption condition toto_revision < trigger_kwargs_encryption_version <= from_revision
:kwargs
and the new revision should be equal to or greater than this revision.kwargs
and the previous revision should be equal to or greater than this revision.