Skip to content
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

Update conf column in dag_run table type from bytes to JSON #44533

Open
wants to merge 40 commits into
base: main
Choose a base branch
from

Conversation

vatsrahul1001
Copy link
Collaborator

closes: #43933


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

@vatsrahul1001 vatsrahul1001 marked this pull request as draft December 1, 2024 13:11
@vatsrahul1001 vatsrahul1001 marked this pull request as ready for review December 2, 2024 10:32
@vatsrahul1001 vatsrahul1001 marked this pull request as draft December 2, 2024 10:33
@vatsrahul1001
Copy link
Collaborator Author

While Testing this I noticed an issue in the downgrade case. We are not removing the data from downgrade and just perform below conversion.

          ALTER TABLE dag_run
          ALTER COLUMN conf TYPE BYTEA
          USING CASE
              WHEN conf IS NOT NULL THEN CONVERT_TO(conf::TEXT, 'UTF8')
              ELSE NULL
          END
 

I am getting UnpicklingError error with this when I try to open DAG page.
image

Should we also move data to the archive table in case of a downgrade as well?
cc: @kaxil

@vatsrahul1001 vatsrahul1001 marked this pull request as ready for review December 2, 2024 13:23
@kaxil
Copy link
Member

kaxil commented Dec 2, 2024

While Testing this I noticed an issue in the downgrade case. We are not removing the data from downgrade and just perform below conversion.

          ALTER TABLE dag_run
          ALTER COLUMN conf TYPE BYTEA
          USING CASE
              WHEN conf IS NOT NULL THEN CONVERT_TO(conf::TEXT, 'UTF8')
              ELSE NULL
          END
 

I am getting UnpicklingError error with this when I try to open DAG page. image

Should we also move data to the archive table in case of a downgrade as well? cc: @kaxil

Yeah, it is different than XCom, because XCom code had handling of both JSON & pickle type -- for dagrun conf it would be different. For downgrade you might just want to insert all records from the archive table back here.

@@ -137,7 +138,7 @@ class DagRun(Base, LoggingMixin):
triggered_by = Column(
Enum(DagRunTriggeredByType, native_enum=False, length=50)
) # Airflow component that triggered the run.
conf = Column(PickleType)
conf = Column(JSON().with_variant(postgresql.JSONB, "postgresql"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not need any more handling than these?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if the DagRun edit view works in the FAB UI

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might need to change this line:

if item.conf:
item.conf = json.loads(item.conf)

Copy link
Member

@kaxil kaxil Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@kaxil kaxil Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vatsrahul1001 vatsrahul1001 added the airflow3.0:breaking Candidates for Airflow 3.0 that contain breaking changes label Dec 3, 2024
kaxil pushed a commit that referenced this pull request Dec 3, 2024
In [PR](#44166) we added migration for removing pickled data from `xcom` table. During my testing I noticed with `SQLite`  [insert](https://github.com/apache/airflow/blob/main/airflow/migrations/versions/0049_3_0_0_remove_pickled_data_from_xcom_table.py#L88) statement is not working in case of upgrade. Changing condition to `hex(substr(value, 1, 1)) = '80'` works. Tested [here](#44533 (comment)).

related: #44166
@jscheffl jscheffl changed the title Update conf column in dag_run table type from bytea to JSON Update conf column in dag_run table type from bytes to JSON Jan 2, 2025
@jscheffl
Copy link
Contributor

jscheffl commented Jan 2, 2025

I don't see why the two failing tests are failing - they are really unrelated to the PR - but they are green on canary builds.
I think the comment from @kaxil requires some double check, else from point of data and migration I am good with it.

@potiuk
Copy link
Member

potiuk commented Jan 2, 2025

I don't see why the two failing tests are failing - they are really unrelated to the PR - but they are green on canary builds. I think the comment from @kaxil requires some double check, else from point of data and migration I am good with it.

Those tests are run with full tests needed so they are very likely going to fail in canary (and for others tests as well after this one is merged. @vatsrahul1001 - if you can rebase it again and ping me when it fails, I might want to have a deeper look or maybe @dabla might take a look.

It definitely comes from #41327 becasue that's where get_primary_keys was introduced.

@potiuk
Copy link
Member

potiuk commented Jan 2, 2025

This is a very interesting one. It looks like for some reason the compat tests were running the version of tests that were there before #41327 - which it should not - tests should always be taken from main.

First time where #45287 might prove to be useful @gopidesupavan !

@potiuk
Copy link
Member

potiuk commented Jan 2, 2025

Ah yeah. I think it just needs rebase.

@vatsrahul1001
Copy link
Collaborator Author

@potiuk I have rebased. Test are running now.

@jscheffl
Copy link
Contributor

jscheffl commented Jan 2, 2025

Oh, we had another issue fixed in #45347 - maybe you need to re-base another time, not generating the same again :-(

@potiuk
Copy link
Member

potiuk commented Jan 2, 2025

Can you rebase AGAIN @vatsrahul1001 :) -> we found and issue with @jscheffl with the new caching scheme - fixed in #45347 that would run "main" version of the tests. So I think that could be the reason

@potiuk
Copy link
Member

potiuk commented Jan 2, 2025

:D @jscheffl -> same thought

@gopidesupavan
Copy link
Member

gopidesupavan commented Jan 2, 2025

This is a very interesting one. It looks like for some reason the compat tests were running the version of tests that were there before #41327 - which it should not - tests should always be taken from main.

First time where #45287 might prove to be useful @gopidesupavan !

I think we are uploading some images differently by seeing workflows?

@potiuk
Copy link
Member

potiuk commented Jan 2, 2025

I think we are uploading some images differently by seeing workflows?

We were not uploading them AT ALL

@potiuk
Copy link
Member

potiuk commented Jan 2, 2025

😱

@potiuk
Copy link
Member

potiuk commented Jan 2, 2025

I am sorry @vatsrahul1001 -> you have to rebase AGAIN - the #45347 caused that #45335 was merged as "green" but it had some issues. It' s now reverted so after you rebase .... you should get a clean green state (minus flaky asyncio test we know about but this one needs further investigation and mostly happens in Python 3.12

@vatsrahul1001
Copy link
Collaborator Author

vatsrahul1001 commented Jan 2, 2025

thanks @jedcunningham. @potiuk all test passed now :)

@potiuk
Copy link
Member

potiuk commented Jan 2, 2025

thanks @jedcunningham. @potiuk all test passed now :)

UFF! Goood.... That was it then :)

@potiuk
Copy link
Member

potiuk commented Jan 2, 2025

BTW. @vatsrahul1001 I also submitted this apache/infrastructure-actions#88 so that in the futur we can protect against similar mistakes (of mine this time). That was a good learning :)

LefterisXefteris pushed a commit to LefterisXefteris/airflow that referenced this pull request Jan 5, 2025
In [PR](apache#44166) we added migration for removing pickled data from `xcom` table. During my testing I noticed with `SQLite`  [insert](https://github.com/apache/airflow/blob/main/airflow/migrations/versions/0049_3_0_0_remove_pickled_data_from_xcom_table.py#L88) statement is not working in case of upgrade. Changing condition to `hex(substr(value, 1, 1)) = '80'` works. Tested [here](apache#44533 (comment)).

related: apache#44166
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:db-migrations PRs with DB migration full tests needed We need to run full set of tests for this PR to merge kind:documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dag_run table - replace column conf type - byte ( that store a python pickle ) by a JSON
6 participants