Support serialization to Pydantic models in Internal API - #30282

Merged
potiuk merged 2 commits into
apache:mainfrom
mhenc:pydantic_internal
Apr 5, 2023
Merged

Support serialization to Pydantic models in Internal API#30282
potiuk merged 2 commits into
apache:mainfrom
mhenc:pydantic_internal

Conversation

@mhenc

Copy link
Copy Markdown
Contributor

Follow-up for #29776

With Pydantic types added to Airflow and changes to LocalTask Job in #30255 we can use serialize TaskInstance/DagRun/DagSet to Pydantic object to be used on client side.

closes: #30240

@mhenc
mhenc marked this pull request as ready for review March 24, 2023 14:11
@mhenc
mhenc requested review from ashb and kaxil as code ownersMarch 24, 2023 14:11
@mhenc

mhenc commented Mar 24, 2023

Copy link
Copy Markdown
ContributorAuthor

cc: @potiuk@vincbeck

@potiukpotiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good.

@potiuk

Copy link
Copy Markdown
Member

I think it would be great to add some unit tests though.

@mhenc

mhenc commented Mar 24, 2023

Copy link
Copy Markdown
ContributorAuthor

Added support for BaseJob and unit tests

@mhenc
mhenc requested a review from potiukMarch 24, 2023 15:01

@vincbeckvincbeck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@ashb

ashb commented Mar 25, 2023

Copy link
Copy Markdown
Member

/cc @bolkedebruin who has been overhauling the serde code for 2.6

@ashb
ashb requested a review from bolkedebruinMarch 25, 2023 09:26

@potiukpotiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@bolkedebruin -> any comments?

A small general comment as I know from offline discussions I know you have reservation to the way AIP-44 in general - even if it is approaved and way in-progress.

I think those changes we do nownicely plugs in SQLAlchemy models into our serialization with super-small cost and maintenance effort needed (as described in the original Pydantic PR #29776 - almost no overhead of code to maintain and nicely piggybacks on battle proven Pydantic - used by very serious projects - wih SQLALchemy and ORM model as the first-class citizen).

I think if we implement it now and follow through with Internal API implementation (for quite a while we will mark it as experimental, I am sure) and my bet is the work we are doing will allow to nicely decouple the DB from the actual code that is run in the worker. Even if we (much) later decide to implement another solution (workload based for example), those changes will not hold us back, but rather make it easier to understand which parts of the process we need to replace in order to make this happen.

I think our changes are specifically aimed in making minimal "surgical" changes to existing code to make also separation-of-concerns better, and then any future discussions might get easier once we complete it.

I think we are not ready to spend time on making more "Architectural" changes now. And I also think what we implement now will make it easier, not harder if we decide to them (for Airflow 3 for example).

I honestly think this is a good way to move it forward :).

@potiuk

Copy link
Copy Markdown
Member

Hey @bolkedebruin - any comments ? I think it nicely (and optionally) plugs in our serialization to add more capabilities we need in AIP-44 so if there will be no more feedback, I am planning to merge that one so that we can proceed.

Comment threadairflow/serialization/serialized_objects.py Outdated
@potiuk

Copy link
Copy Markdown
Member

I assume no news is a good news and merge this one once it passes (I rebased to apply fix to pytest collection timeout from today)., @uranusjr -> maybe alse we could start merging the decoupling:

#30255 -> #30302 -> #30308 -> #30376

It starts to hold us back quite a lot and I would love to progress with AIP-44 implementation.

@potiuk

Copy link
Copy Markdown
Member

Looks good. Merging. I decided also to move the Pydantic classes to serialization as suggested by @uranusjr as immediate follow-up. Any conflicts there will be super-easy to solve as those will be only imports - In my refactoring, I barely touch those classes now after removing globals stuff recently.

@potiuk

Copy link
Copy Markdown
Member

Though - I see this PR has fallen victim of the "UI Rebase bug" from GitHub @mhenc can you please re-push your branch after manual rebase?

@potiuk
potiuk merged commit 41c8e58 into apache:mainApr 5, 2023
@mhenc
mhenc deleted the pydantic_internal branch April 5, 2023 13:39
@bolkedebruin

bolkedebruin commented Apr 6, 2023

Copy link
Copy Markdown
Contributor

If someone can tell me how to setup gmail filters so these notifications get somewhere visible I'd appreciate it :/. My comment would be why this is tied to the old serialization? I understand it is merged of course, because I think earlier (other PR related to this AIP) we agreed upon not extending the old serializer.

@potiuk

Copy link
Copy Markdown
Member

Where should we add it ? - we can still move it (I have not followed the serialisation discussion earlier but I am eager to learn :).

I would suggest to add "@bolkedebruin" in "contains word" and make sure it is flagged as important, not skip inbox etc.

@bolkedebruin

Copy link
Copy Markdown
Contributor

Thanks, I'll try that.

In an earlier discussion @mhenc added some functionality to the old serializer on the basis of that rebasing on the current serializer, which supports versioning, is an order of magnitude faster, and is more flexible and maintainable, was too much impact. I agreed on the condition (i think explicitly) that we then wouldn't add more functionality to the old serializer. However, I don't consider this a small change anymore. So, I wonder what the reasoning was and maybe the suggestion is to at least provide the same functionality in the new serializer if we really need this now.

@potiuk

potiuk commented Apr 6, 2023

Copy link
Copy Markdown
Member

What's the new vs. old serialization @bolkedebruin?

Sorry I have not paid too much attention. I looked through the code now - do I understand correctly (correct me if I am wrong) that the change is to separate serializer "type"s into separate modules in the "serializer" package and we register them dynamically in serde._register() - discovering the different "serializers" we have there ? In this case we would then have "pydantic.py" module in "serializers" and use "serde.serialize/deserialize" to serialize such objects instead of BaseSerialization.serialize/deserialize?

That sounds very reasonable approach IMHO - and I like it a lot more than the if/elif approach in the BaseSerializer (if I correctly understand it).

So @mhenc - is there a reason why we would not be able to do that? Because if that's the future direcrion of our serialization then I'd be in favour of doing so (unless there are some resons we would not like/or couldn't do it). I think we are anyhow heading now for 2.7 with AIP-44, so even if it means a bit more refactoring and testing, that would make more sense.

@bolkedebruin

Copy link
Copy Markdown
Contributor

@potiuk Yes, you are generally correct. In @mhenc defense there could be reasons to not integrate with the new serializer yet, basically if you rely on DAG serialization which I haven't completed yet. Yet, extending the old serialization significantly seems odd.

@potiuk

potiuk commented Apr 6, 2023

Copy link
Copy Markdown
Member

@potiuk Yes, you are generally correct. In @mhenc defense there could be reasons to not integrate with the new serializer yet, basically if you rely on DAG serialization which I haven't completed yet. Yet, extending the old serialization significantly seems odd.

I think we can remove that part for now since we are anyhow moving it behind a feature flag as 2.6.0 is going to happen before we manage to merge outstanding changes and complete testing #30509#30510

@potiuk

Copy link
Copy Markdown
Member

Once we merge #30509#30510 we can put it behind AIP-44 feature flag and we can swap it out when the new serialization is ready.

@mhenc

mhenc commented Apr 7, 2023

Copy link
Copy Markdown
ContributorAuthor

Yes, I still plan to integrate with new serialization, this PR was just to unblock any work with AIP-44.
I remember when we talked about that a while ago it was still under development.
Let me check if we rely on DAG Serialization (I think we don't). So I can work now on replacing the serialization framework for AIP-44.

@potiuk

potiuk commented Apr 7, 2023

Copy link
Copy Markdown
Member

Yeah. You can start with putting the change here behind _ENABLE_AIP_44 feature flag, so that we know this part is not used, until we replace it with the "new" serialization (and we can leave TODO: comment to remove it once we switch to the new one).

@ephraimbuddyephraimbuddy added changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) AIP-44 Airflow Internal API labels Apr 11, 2023
@bolkedebruin

Copy link
Copy Markdown
Contributor

Thx :-)

@potiuk

Copy link
Copy Markdown
Member

Thx :-)

yep. Feature flag nicely implemented here to start with and I will let @mhenc to explore switching to the new serializer #30560

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIP-44Airflow Internal APIarea:serializationchangelog:skipChanges that should be skipped from the changelog (CI, tests, etc..)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AIP-44 Implement conversion to Pydantic-ORM objects in Internal API

7 participants

@mhenc@potiuk@ashb@bolkedebruin@uranusjr@vincbeck@ephraimbuddy
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Support serialization to Pydantic models in Internal API - #30282

Merged
potiuk merged 2 commits into
apache:mainfrom
mhenc:pydantic_internal
Apr 5, 2023
Merged

Support serialization to Pydantic models in Internal API#30282
potiuk merged 2 commits into
apache:mainfrom
mhenc:pydantic_internal

Conversation

@mhenc

Copy link
Copy Markdown
Contributor

Follow-up for #29776

With Pydantic types added to Airflow and changes to LocalTask Job in #30255 we can use serialize TaskInstance/DagRun/DagSet to Pydantic object to be used on client side.

closes: #30240

@mhenc
mhenc marked this pull request as ready for review March 24, 2023 14:11
@mhenc
mhenc requested review from ashb and kaxil as code ownersMarch 24, 2023 14:11
@mhenc

mhenc commented Mar 24, 2023

Copy link
Copy Markdown
ContributorAuthor

cc: @potiuk@vincbeck

@potiukpotiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good.

@potiuk

Copy link
Copy Markdown
Member

I think it would be great to add some unit tests though.

@mhenc

mhenc commented Mar 24, 2023

Copy link
Copy Markdown
ContributorAuthor

Added support for BaseJob and unit tests

@mhenc
mhenc requested a review from potiukMarch 24, 2023 15:01

@vincbeckvincbeck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@ashb

ashb commented Mar 25, 2023

Copy link
Copy Markdown
Member

/cc @bolkedebruin who has been overhauling the serde code for 2.6

@ashb
ashb requested a review from bolkedebruinMarch 25, 2023 09:26

@potiukpotiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@bolkedebruin -> any comments?

A small general comment as I know from offline discussions I know you have reservation to the way AIP-44 in general - even if it is approaved and way in-progress.

I think those changes we do nownicely plugs in SQLAlchemy models into our serialization with super-small cost and maintenance effort needed (as described in the original Pydantic PR #29776 - almost no overhead of code to maintain and nicely piggybacks on battle proven Pydantic - used by very serious projects - wih SQLALchemy and ORM model as the first-class citizen).

I think if we implement it now and follow through with Internal API implementation (for quite a while we will mark it as experimental, I am sure) and my bet is the work we are doing will allow to nicely decouple the DB from the actual code that is run in the worker. Even if we (much) later decide to implement another solution (workload based for example), those changes will not hold us back, but rather make it easier to understand which parts of the process we need to replace in order to make this happen.

I think our changes are specifically aimed in making minimal "surgical" changes to existing code to make also separation-of-concerns better, and then any future discussions might get easier once we complete it.

I think we are not ready to spend time on making more "Architectural" changes now. And I also think what we implement now will make it easier, not harder if we decide to them (for Airflow 3 for example).

I honestly think this is a good way to move it forward :).

@potiuk

Copy link
Copy Markdown
Member

Hey @bolkedebruin - any comments ? I think it nicely (and optionally) plugs in our serialization to add more capabilities we need in AIP-44 so if there will be no more feedback, I am planning to merge that one so that we can proceed.

Comment threadairflow/serialization/serialized_objects.py Outdated
@potiuk

Copy link
Copy Markdown
Member

I assume no news is a good news and merge this one once it passes (I rebased to apply fix to pytest collection timeout from today)., @uranusjr -> maybe alse we could start merging the decoupling:

#30255 -> #30302 -> #30308 -> #30376

It starts to hold us back quite a lot and I would love to progress with AIP-44 implementation.

@potiuk

Copy link
Copy Markdown
Member

Looks good. Merging. I decided also to move the Pydantic classes to serialization as suggested by @uranusjr as immediate follow-up. Any conflicts there will be super-easy to solve as those will be only imports - In my refactoring, I barely touch those classes now after removing globals stuff recently.

@potiuk

Copy link
Copy Markdown
Member

Though - I see this PR has fallen victim of the "UI Rebase bug" from GitHub @mhenc can you please re-push your branch after manual rebase?

@potiuk
potiuk merged commit 41c8e58 into apache:mainApr 5, 2023
@mhenc
mhenc deleted the pydantic_internal branch April 5, 2023 13:39
@bolkedebruin

bolkedebruin commented Apr 6, 2023

Copy link
Copy Markdown
Contributor

If someone can tell me how to setup gmail filters so these notifications get somewhere visible I'd appreciate it :/. My comment would be why this is tied to the old serialization? I understand it is merged of course, because I think earlier (other PR related to this AIP) we agreed upon not extending the old serializer.

@potiuk

Copy link
Copy Markdown
Member

Where should we add it ? - we can still move it (I have not followed the serialisation discussion earlier but I am eager to learn :).

I would suggest to add "@bolkedebruin" in "contains word" and make sure it is flagged as important, not skip inbox etc.

@bolkedebruin

Copy link
Copy Markdown
Contributor

Thanks, I'll try that.

In an earlier discussion @mhenc added some functionality to the old serializer on the basis of that rebasing on the current serializer, which supports versioning, is an order of magnitude faster, and is more flexible and maintainable, was too much impact. I agreed on the condition (i think explicitly) that we then wouldn't add more functionality to the old serializer. However, I don't consider this a small change anymore. So, I wonder what the reasoning was and maybe the suggestion is to at least provide the same functionality in the new serializer if we really need this now.

@potiuk

potiuk commented Apr 6, 2023

Copy link
Copy Markdown
Member

What's the new vs. old serialization @bolkedebruin?

Sorry I have not paid too much attention. I looked through the code now - do I understand correctly (correct me if I am wrong) that the change is to separate serializer "type"s into separate modules in the "serializer" package and we register them dynamically in serde._register() - discovering the different "serializers" we have there ? In this case we would then have "pydantic.py" module in "serializers" and use "serde.serialize/deserialize" to serialize such objects instead of BaseSerialization.serialize/deserialize?

That sounds very reasonable approach IMHO - and I like it a lot more than the if/elif approach in the BaseSerializer (if I correctly understand it).

So @mhenc - is there a reason why we would not be able to do that? Because if that's the future direcrion of our serialization then I'd be in favour of doing so (unless there are some resons we would not like/or couldn't do it). I think we are anyhow heading now for 2.7 with AIP-44, so even if it means a bit more refactoring and testing, that would make more sense.

@bolkedebruin

Copy link
Copy Markdown
Contributor

@potiuk Yes, you are generally correct. In @mhenc defense there could be reasons to not integrate with the new serializer yet, basically if you rely on DAG serialization which I haven't completed yet. Yet, extending the old serialization significantly seems odd.

@potiuk

potiuk commented Apr 6, 2023

Copy link
Copy Markdown
Member

@potiuk Yes, you are generally correct. In @mhenc defense there could be reasons to not integrate with the new serializer yet, basically if you rely on DAG serialization which I haven't completed yet. Yet, extending the old serialization significantly seems odd.

I think we can remove that part for now since we are anyhow moving it behind a feature flag as 2.6.0 is going to happen before we manage to merge outstanding changes and complete testing #30509#30510

@potiuk

Copy link
Copy Markdown
Member

Once we merge #30509#30510 we can put it behind AIP-44 feature flag and we can swap it out when the new serialization is ready.

@mhenc

mhenc commented Apr 7, 2023

Copy link
Copy Markdown
ContributorAuthor

Yes, I still plan to integrate with new serialization, this PR was just to unblock any work with AIP-44.
I remember when we talked about that a while ago it was still under development.
Let me check if we rely on DAG Serialization (I think we don't). So I can work now on replacing the serialization framework for AIP-44.

@potiuk

potiuk commented Apr 7, 2023

Copy link
Copy Markdown
Member

Yeah. You can start with putting the change here behind _ENABLE_AIP_44 feature flag, so that we know this part is not used, until we replace it with the "new" serialization (and we can leave TODO: comment to remove it once we switch to the new one).

@ephraimbuddyephraimbuddy added changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) AIP-44 Airflow Internal API labels Apr 11, 2023
@bolkedebruin

Copy link
Copy Markdown
Contributor

Thx :-)

@potiuk

Copy link
Copy Markdown
Member

Thx :-)

yep. Feature flag nicely implemented here to start with and I will let @mhenc to explore switching to the new serializer #30560

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIP-44Airflow Internal APIarea:serializationchangelog:skipChanges that should be skipped from the changelog (CI, tests, etc..)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AIP-44 Implement conversion to Pydantic-ORM objects in Internal API

7 participants

@mhenc@potiuk@ashb@bolkedebruin@uranusjr@vincbeck@ephraimbuddy
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Support serialization to Pydantic models in Internal API - #30282

Merged
potiuk merged 2 commits into
apache:mainfrom
mhenc:pydantic_internal
Apr 5, 2023
Merged

Support serialization to Pydantic models in Internal API#30282
potiuk merged 2 commits into
apache:mainfrom
mhenc:pydantic_internal

Conversation

@mhenc

Copy link
Copy Markdown
Contributor

Follow-up for #29776

With Pydantic types added to Airflow and changes to LocalTask Job in #30255 we can use serialize TaskInstance/DagRun/DagSet to Pydantic object to be used on client side.

closes: #30240

@mhenc
mhenc marked this pull request as ready for review March 24, 2023 14:11
@mhenc
mhenc requested review from ashb and kaxil as code ownersMarch 24, 2023 14:11
@mhenc

mhenc commented Mar 24, 2023

Copy link
Copy Markdown
ContributorAuthor

cc: @potiuk@vincbeck

@potiukpotiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good.

@potiuk

Copy link
Copy Markdown
Member

I think it would be great to add some unit tests though.

@mhenc

mhenc commented Mar 24, 2023

Copy link
Copy Markdown
ContributorAuthor

Added support for BaseJob and unit tests

@mhenc
mhenc requested a review from potiukMarch 24, 2023 15:01

@vincbeckvincbeck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@ashb

ashb commented Mar 25, 2023

Copy link
Copy Markdown
Member

/cc @bolkedebruin who has been overhauling the serde code for 2.6

@ashb
ashb requested a review from bolkedebruinMarch 25, 2023 09:26

@potiukpotiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@bolkedebruin -> any comments?

A small general comment as I know from offline discussions I know you have reservation to the way AIP-44 in general - even if it is approaved and way in-progress.

I think those changes we do nownicely plugs in SQLAlchemy models into our serialization with super-small cost and maintenance effort needed (as described in the original Pydantic PR #29776 - almost no overhead of code to maintain and nicely piggybacks on battle proven Pydantic - used by very serious projects - wih SQLALchemy and ORM model as the first-class citizen).

I think if we implement it now and follow through with Internal API implementation (for quite a while we will mark it as experimental, I am sure) and my bet is the work we are doing will allow to nicely decouple the DB from the actual code that is run in the worker. Even if we (much) later decide to implement another solution (workload based for example), those changes will not hold us back, but rather make it easier to understand which parts of the process we need to replace in order to make this happen.

I think our changes are specifically aimed in making minimal "surgical" changes to existing code to make also separation-of-concerns better, and then any future discussions might get easier once we complete it.

I think we are not ready to spend time on making more "Architectural" changes now. And I also think what we implement now will make it easier, not harder if we decide to them (for Airflow 3 for example).

I honestly think this is a good way to move it forward :).

@potiuk

Copy link
Copy Markdown
Member

Hey @bolkedebruin - any comments ? I think it nicely (and optionally) plugs in our serialization to add more capabilities we need in AIP-44 so if there will be no more feedback, I am planning to merge that one so that we can proceed.

Comment threadairflow/serialization/serialized_objects.py Outdated
@potiuk

Copy link
Copy Markdown
Member

I assume no news is a good news and merge this one once it passes (I rebased to apply fix to pytest collection timeout from today)., @uranusjr -> maybe alse we could start merging the decoupling:

#30255 -> #30302 -> #30308 -> #30376

It starts to hold us back quite a lot and I would love to progress with AIP-44 implementation.

@potiuk

Copy link
Copy Markdown
Member

Looks good. Merging. I decided also to move the Pydantic classes to serialization as suggested by @uranusjr as immediate follow-up. Any conflicts there will be super-easy to solve as those will be only imports - In my refactoring, I barely touch those classes now after removing globals stuff recently.

@potiuk

Copy link
Copy Markdown
Member

Though - I see this PR has fallen victim of the "UI Rebase bug" from GitHub @mhenc can you please re-push your branch after manual rebase?

@potiuk
potiuk merged commit 41c8e58 into apache:mainApr 5, 2023
@mhenc
mhenc deleted the pydantic_internal branch April 5, 2023 13:39
@bolkedebruin

bolkedebruin commented Apr 6, 2023

Copy link
Copy Markdown
Contributor

If someone can tell me how to setup gmail filters so these notifications get somewhere visible I'd appreciate it :/. My comment would be why this is tied to the old serialization? I understand it is merged of course, because I think earlier (other PR related to this AIP) we agreed upon not extending the old serializer.

@potiuk

Copy link
Copy Markdown
Member

Where should we add it ? - we can still move it (I have not followed the serialisation discussion earlier but I am eager to learn :).

I would suggest to add "@bolkedebruin" in "contains word" and make sure it is flagged as important, not skip inbox etc.

@bolkedebruin

Copy link
Copy Markdown
Contributor

Thanks, I'll try that.

In an earlier discussion @mhenc added some functionality to the old serializer on the basis of that rebasing on the current serializer, which supports versioning, is an order of magnitude faster, and is more flexible and maintainable, was too much impact. I agreed on the condition (i think explicitly) that we then wouldn't add more functionality to the old serializer. However, I don't consider this a small change anymore. So, I wonder what the reasoning was and maybe the suggestion is to at least provide the same functionality in the new serializer if we really need this now.

@potiuk

potiuk commented Apr 6, 2023

Copy link
Copy Markdown
Member

What's the new vs. old serialization @bolkedebruin?

Sorry I have not paid too much attention. I looked through the code now - do I understand correctly (correct me if I am wrong) that the change is to separate serializer "type"s into separate modules in the "serializer" package and we register them dynamically in serde._register() - discovering the different "serializers" we have there ? In this case we would then have "pydantic.py" module in "serializers" and use "serde.serialize/deserialize" to serialize such objects instead of BaseSerialization.serialize/deserialize?

That sounds very reasonable approach IMHO - and I like it a lot more than the if/elif approach in the BaseSerializer (if I correctly understand it).

So @mhenc - is there a reason why we would not be able to do that? Because if that's the future direcrion of our serialization then I'd be in favour of doing so (unless there are some resons we would not like/or couldn't do it). I think we are anyhow heading now for 2.7 with AIP-44, so even if it means a bit more refactoring and testing, that would make more sense.

@bolkedebruin

Copy link
Copy Markdown
Contributor

@potiuk Yes, you are generally correct. In @mhenc defense there could be reasons to not integrate with the new serializer yet, basically if you rely on DAG serialization which I haven't completed yet. Yet, extending the old serialization significantly seems odd.

@potiuk

potiuk commented Apr 6, 2023

Copy link
Copy Markdown
Member

@potiuk Yes, you are generally correct. In @mhenc defense there could be reasons to not integrate with the new serializer yet, basically if you rely on DAG serialization which I haven't completed yet. Yet, extending the old serialization significantly seems odd.

I think we can remove that part for now since we are anyhow moving it behind a feature flag as 2.6.0 is going to happen before we manage to merge outstanding changes and complete testing #30509#30510

@potiuk

Copy link
Copy Markdown
Member

Once we merge #30509#30510 we can put it behind AIP-44 feature flag and we can swap it out when the new serialization is ready.

@mhenc

mhenc commented Apr 7, 2023

Copy link
Copy Markdown
ContributorAuthor

Yes, I still plan to integrate with new serialization, this PR was just to unblock any work with AIP-44.
I remember when we talked about that a while ago it was still under development.
Let me check if we rely on DAG Serialization (I think we don't). So I can work now on replacing the serialization framework for AIP-44.

@potiuk

potiuk commented Apr 7, 2023

Copy link
Copy Markdown
Member

Yeah. You can start with putting the change here behind _ENABLE_AIP_44 feature flag, so that we know this part is not used, until we replace it with the "new" serialization (and we can leave TODO: comment to remove it once we switch to the new one).

@ephraimbuddyephraimbuddy added changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) AIP-44 Airflow Internal API labels Apr 11, 2023
@bolkedebruin

Copy link
Copy Markdown
Contributor

Thx :-)

@potiuk

Copy link
Copy Markdown
Member

Thx :-)

yep. Feature flag nicely implemented here to start with and I will let @mhenc to explore switching to the new serializer #30560

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIP-44Airflow Internal APIarea:serializationchangelog:skipChanges that should be skipped from the changelog (CI, tests, etc..)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AIP-44 Implement conversion to Pydantic-ORM objects in Internal API

7 participants

@mhenc@potiuk@ashb@bolkedebruin@uranusjr@vincbeck@ephraimbuddy
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Support serialization to Pydantic models in Internal API - #30282

Merged
potiuk merged 2 commits into
apache:mainfrom
mhenc:pydantic_internal
Apr 5, 2023
Merged

Support serialization to Pydantic models in Internal API#30282
potiuk merged 2 commits into
apache:mainfrom
mhenc:pydantic_internal

Conversation

@mhenc

Copy link
Copy Markdown
Contributor

Follow-up for #29776

With Pydantic types added to Airflow and changes to LocalTask Job in #30255 we can use serialize TaskInstance/DagRun/DagSet to Pydantic object to be used on client side.

closes: #30240

@mhenc
mhenc marked this pull request as ready for review March 24, 2023 14:11
@mhenc
mhenc requested review from ashb and kaxil as code ownersMarch 24, 2023 14:11
@mhenc

mhenc commented Mar 24, 2023

Copy link
Copy Markdown
ContributorAuthor

cc: @potiuk@vincbeck

@potiukpotiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good.

@potiuk

Copy link
Copy Markdown
Member

I think it would be great to add some unit tests though.

@mhenc

mhenc commented Mar 24, 2023

Copy link
Copy Markdown
ContributorAuthor

Added support for BaseJob and unit tests

@mhenc
mhenc requested a review from potiukMarch 24, 2023 15:01

@vincbeckvincbeck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@ashb

ashb commented Mar 25, 2023

Copy link
Copy Markdown
Member

/cc @bolkedebruin who has been overhauling the serde code for 2.6

@ashb
ashb requested a review from bolkedebruinMarch 25, 2023 09:26

@potiukpotiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@bolkedebruin -> any comments?

A small general comment as I know from offline discussions I know you have reservation to the way AIP-44 in general - even if it is approaved and way in-progress.

I think those changes we do nownicely plugs in SQLAlchemy models into our serialization with super-small cost and maintenance effort needed (as described in the original Pydantic PR #29776 - almost no overhead of code to maintain and nicely piggybacks on battle proven Pydantic - used by very serious projects - wih SQLALchemy and ORM model as the first-class citizen).

I think if we implement it now and follow through with Internal API implementation (for quite a while we will mark it as experimental, I am sure) and my bet is the work we are doing will allow to nicely decouple the DB from the actual code that is run in the worker. Even if we (much) later decide to implement another solution (workload based for example), those changes will not hold us back, but rather make it easier to understand which parts of the process we need to replace in order to make this happen.

I think our changes are specifically aimed in making minimal "surgical" changes to existing code to make also separation-of-concerns better, and then any future discussions might get easier once we complete it.

I think we are not ready to spend time on making more "Architectural" changes now. And I also think what we implement now will make it easier, not harder if we decide to them (for Airflow 3 for example).

I honestly think this is a good way to move it forward :).

@potiuk

Copy link
Copy Markdown
Member

Hey @bolkedebruin - any comments ? I think it nicely (and optionally) plugs in our serialization to add more capabilities we need in AIP-44 so if there will be no more feedback, I am planning to merge that one so that we can proceed.

Comment threadairflow/serialization/serialized_objects.py Outdated
@potiuk

Copy link
Copy Markdown
Member

I assume no news is a good news and merge this one once it passes (I rebased to apply fix to pytest collection timeout from today)., @uranusjr -> maybe alse we could start merging the decoupling:

#30255 -> #30302 -> #30308 -> #30376

It starts to hold us back quite a lot and I would love to progress with AIP-44 implementation.

@potiuk

Copy link
Copy Markdown
Member

Looks good. Merging. I decided also to move the Pydantic classes to serialization as suggested by @uranusjr as immediate follow-up. Any conflicts there will be super-easy to solve as those will be only imports - In my refactoring, I barely touch those classes now after removing globals stuff recently.

@potiuk

Copy link
Copy Markdown
Member

Though - I see this PR has fallen victim of the "UI Rebase bug" from GitHub @mhenc can you please re-push your branch after manual rebase?

@potiuk
potiuk merged commit 41c8e58 into apache:mainApr 5, 2023
@mhenc
mhenc deleted the pydantic_internal branch April 5, 2023 13:39
@bolkedebruin

bolkedebruin commented Apr 6, 2023

Copy link
Copy Markdown
Contributor

If someone can tell me how to setup gmail filters so these notifications get somewhere visible I'd appreciate it :/. My comment would be why this is tied to the old serialization? I understand it is merged of course, because I think earlier (other PR related to this AIP) we agreed upon not extending the old serializer.

@potiuk

Copy link
Copy Markdown
Member

Where should we add it ? - we can still move it (I have not followed the serialisation discussion earlier but I am eager to learn :).

I would suggest to add "@bolkedebruin" in "contains word" and make sure it is flagged as important, not skip inbox etc.

@bolkedebruin

Copy link
Copy Markdown
Contributor

Thanks, I'll try that.

In an earlier discussion @mhenc added some functionality to the old serializer on the basis of that rebasing on the current serializer, which supports versioning, is an order of magnitude faster, and is more flexible and maintainable, was too much impact. I agreed on the condition (i think explicitly) that we then wouldn't add more functionality to the old serializer. However, I don't consider this a small change anymore. So, I wonder what the reasoning was and maybe the suggestion is to at least provide the same functionality in the new serializer if we really need this now.

@potiuk

potiuk commented Apr 6, 2023

Copy link
Copy Markdown
Member

What's the new vs. old serialization @bolkedebruin?

Sorry I have not paid too much attention. I looked through the code now - do I understand correctly (correct me if I am wrong) that the change is to separate serializer "type"s into separate modules in the "serializer" package and we register them dynamically in serde._register() - discovering the different "serializers" we have there ? In this case we would then have "pydantic.py" module in "serializers" and use "serde.serialize/deserialize" to serialize such objects instead of BaseSerialization.serialize/deserialize?

That sounds very reasonable approach IMHO - and I like it a lot more than the if/elif approach in the BaseSerializer (if I correctly understand it).

So @mhenc - is there a reason why we would not be able to do that? Because if that's the future direcrion of our serialization then I'd be in favour of doing so (unless there are some resons we would not like/or couldn't do it). I think we are anyhow heading now for 2.7 with AIP-44, so even if it means a bit more refactoring and testing, that would make more sense.

@bolkedebruin

Copy link
Copy Markdown
Contributor

@potiuk Yes, you are generally correct. In @mhenc defense there could be reasons to not integrate with the new serializer yet, basically if you rely on DAG serialization which I haven't completed yet. Yet, extending the old serialization significantly seems odd.

@potiuk

potiuk commented Apr 6, 2023

Copy link
Copy Markdown
Member

@potiuk Yes, you are generally correct. In @mhenc defense there could be reasons to not integrate with the new serializer yet, basically if you rely on DAG serialization which I haven't completed yet. Yet, extending the old serialization significantly seems odd.

I think we can remove that part for now since we are anyhow moving it behind a feature flag as 2.6.0 is going to happen before we manage to merge outstanding changes and complete testing #30509#30510

@potiuk

Copy link
Copy Markdown
Member

Once we merge #30509#30510 we can put it behind AIP-44 feature flag and we can swap it out when the new serialization is ready.

@mhenc

mhenc commented Apr 7, 2023

Copy link
Copy Markdown
ContributorAuthor

Yes, I still plan to integrate with new serialization, this PR was just to unblock any work with AIP-44.
I remember when we talked about that a while ago it was still under development.
Let me check if we rely on DAG Serialization (I think we don't). So I can work now on replacing the serialization framework for AIP-44.

@potiuk

potiuk commented Apr 7, 2023

Copy link
Copy Markdown
Member

Yeah. You can start with putting the change here behind _ENABLE_AIP_44 feature flag, so that we know this part is not used, until we replace it with the "new" serialization (and we can leave TODO: comment to remove it once we switch to the new one).

@ephraimbuddyephraimbuddy added changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) AIP-44 Airflow Internal API labels Apr 11, 2023
@bolkedebruin

Copy link
Copy Markdown
Contributor

Thx :-)

@potiuk

Copy link
Copy Markdown
Member

Thx :-)

yep. Feature flag nicely implemented here to start with and I will let @mhenc to explore switching to the new serializer #30560

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIP-44Airflow Internal APIarea:serializationchangelog:skipChanges that should be skipped from the changelog (CI, tests, etc..)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AIP-44 Implement conversion to Pydantic-ORM objects in Internal API

7 participants

@mhenc@potiuk@ashb@bolkedebruin@uranusjr@vincbeck@ephraimbuddy
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Support serialization to Pydantic models in Internal API - #30282

Merged
potiuk merged 2 commits into
apache:mainfrom
mhenc:pydantic_internal
Apr 5, 2023
Merged

Support serialization to Pydantic models in Internal API#30282
potiuk merged 2 commits into
apache:mainfrom
mhenc:pydantic_internal

Conversation

@mhenc

Copy link
Copy Markdown
Contributor

Follow-up for #29776

With Pydantic types added to Airflow and changes to LocalTask Job in #30255 we can use serialize TaskInstance/DagRun/DagSet to Pydantic object to be used on client side.

closes: #30240

@mhenc
mhenc marked this pull request as ready for review March 24, 2023 14:11
@mhenc
mhenc requested review from ashb and kaxil as code ownersMarch 24, 2023 14:11
@mhenc

mhenc commented Mar 24, 2023

Copy link
Copy Markdown
ContributorAuthor

cc: @potiuk@vincbeck

@potiukpotiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good.

@potiuk

Copy link
Copy Markdown
Member

I think it would be great to add some unit tests though.

@mhenc

mhenc commented Mar 24, 2023

Copy link
Copy Markdown
ContributorAuthor

Added support for BaseJob and unit tests

@mhenc
mhenc requested a review from potiukMarch 24, 2023 15:01

@vincbeckvincbeck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@ashb

ashb commented Mar 25, 2023

Copy link
Copy Markdown
Member

/cc @bolkedebruin who has been overhauling the serde code for 2.6

@ashb
ashb requested a review from bolkedebruinMarch 25, 2023 09:26

@potiukpotiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@bolkedebruin -> any comments?

A small general comment as I know from offline discussions I know you have reservation to the way AIP-44 in general - even if it is approaved and way in-progress.

I think those changes we do nownicely plugs in SQLAlchemy models into our serialization with super-small cost and maintenance effort needed (as described in the original Pydantic PR #29776 - almost no overhead of code to maintain and nicely piggybacks on battle proven Pydantic - used by very serious projects - wih SQLALchemy and ORM model as the first-class citizen).

I think if we implement it now and follow through with Internal API implementation (for quite a while we will mark it as experimental, I am sure) and my bet is the work we are doing will allow to nicely decouple the DB from the actual code that is run in the worker. Even if we (much) later decide to implement another solution (workload based for example), those changes will not hold us back, but rather make it easier to understand which parts of the process we need to replace in order to make this happen.

I think our changes are specifically aimed in making minimal "surgical" changes to existing code to make also separation-of-concerns better, and then any future discussions might get easier once we complete it.

I think we are not ready to spend time on making more "Architectural" changes now. And I also think what we implement now will make it easier, not harder if we decide to them (for Airflow 3 for example).

I honestly think this is a good way to move it forward :).

@potiuk

Copy link
Copy Markdown
Member

Hey @bolkedebruin - any comments ? I think it nicely (and optionally) plugs in our serialization to add more capabilities we need in AIP-44 so if there will be no more feedback, I am planning to merge that one so that we can proceed.

Comment threadairflow/serialization/serialized_objects.py Outdated
@potiuk

Copy link
Copy Markdown
Member

I assume no news is a good news and merge this one once it passes (I rebased to apply fix to pytest collection timeout from today)., @uranusjr -> maybe alse we could start merging the decoupling:

#30255 -> #30302 -> #30308 -> #30376

It starts to hold us back quite a lot and I would love to progress with AIP-44 implementation.

@potiuk

Copy link
Copy Markdown
Member

Looks good. Merging. I decided also to move the Pydantic classes to serialization as suggested by @uranusjr as immediate follow-up. Any conflicts there will be super-easy to solve as those will be only imports - In my refactoring, I barely touch those classes now after removing globals stuff recently.

@potiuk

Copy link
Copy Markdown
Member

Though - I see this PR has fallen victim of the "UI Rebase bug" from GitHub @mhenc can you please re-push your branch after manual rebase?

@potiuk
potiuk merged commit 41c8e58 into apache:mainApr 5, 2023
@mhenc
mhenc deleted the pydantic_internal branch April 5, 2023 13:39
@bolkedebruin

bolkedebruin commented Apr 6, 2023

Copy link
Copy Markdown
Contributor

If someone can tell me how to setup gmail filters so these notifications get somewhere visible I'd appreciate it :/. My comment would be why this is tied to the old serialization? I understand it is merged of course, because I think earlier (other PR related to this AIP) we agreed upon not extending the old serializer.

@potiuk

Copy link
Copy Markdown
Member

Where should we add it ? - we can still move it (I have not followed the serialisation discussion earlier but I am eager to learn :).

I would suggest to add "@bolkedebruin" in "contains word" and make sure it is flagged as important, not skip inbox etc.

@bolkedebruin

Copy link
Copy Markdown
Contributor

Thanks, I'll try that.

In an earlier discussion @mhenc added some functionality to the old serializer on the basis of that rebasing on the current serializer, which supports versioning, is an order of magnitude faster, and is more flexible and maintainable, was too much impact. I agreed on the condition (i think explicitly) that we then wouldn't add more functionality to the old serializer. However, I don't consider this a small change anymore. So, I wonder what the reasoning was and maybe the suggestion is to at least provide the same functionality in the new serializer if we really need this now.

@potiuk

potiuk commented Apr 6, 2023

Copy link
Copy Markdown
Member

What's the new vs. old serialization @bolkedebruin?

Sorry I have not paid too much attention. I looked through the code now - do I understand correctly (correct me if I am wrong) that the change is to separate serializer "type"s into separate modules in the "serializer" package and we register them dynamically in serde._register() - discovering the different "serializers" we have there ? In this case we would then have "pydantic.py" module in "serializers" and use "serde.serialize/deserialize" to serialize such objects instead of BaseSerialization.serialize/deserialize?

That sounds very reasonable approach IMHO - and I like it a lot more than the if/elif approach in the BaseSerializer (if I correctly understand it).

So @mhenc - is there a reason why we would not be able to do that? Because if that's the future direcrion of our serialization then I'd be in favour of doing so (unless there are some resons we would not like/or couldn't do it). I think we are anyhow heading now for 2.7 with AIP-44, so even if it means a bit more refactoring and testing, that would make more sense.

@bolkedebruin

Copy link
Copy Markdown
Contributor

@potiuk Yes, you are generally correct. In @mhenc defense there could be reasons to not integrate with the new serializer yet, basically if you rely on DAG serialization which I haven't completed yet. Yet, extending the old serialization significantly seems odd.

@potiuk

potiuk commented Apr 6, 2023

Copy link
Copy Markdown
Member

@potiuk Yes, you are generally correct. In @mhenc defense there could be reasons to not integrate with the new serializer yet, basically if you rely on DAG serialization which I haven't completed yet. Yet, extending the old serialization significantly seems odd.

I think we can remove that part for now since we are anyhow moving it behind a feature flag as 2.6.0 is going to happen before we manage to merge outstanding changes and complete testing #30509#30510

@potiuk

Copy link
Copy Markdown
Member

Once we merge #30509#30510 we can put it behind AIP-44 feature flag and we can swap it out when the new serialization is ready.

@mhenc

mhenc commented Apr 7, 2023

Copy link
Copy Markdown
ContributorAuthor

Yes, I still plan to integrate with new serialization, this PR was just to unblock any work with AIP-44.
I remember when we talked about that a while ago it was still under development.
Let me check if we rely on DAG Serialization (I think we don't). So I can work now on replacing the serialization framework for AIP-44.

@potiuk

potiuk commented Apr 7, 2023

Copy link
Copy Markdown
Member

Yeah. You can start with putting the change here behind _ENABLE_AIP_44 feature flag, so that we know this part is not used, until we replace it with the "new" serialization (and we can leave TODO: comment to remove it once we switch to the new one).

@ephraimbuddyephraimbuddy added changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) AIP-44 Airflow Internal API labels Apr 11, 2023
@bolkedebruin

Copy link
Copy Markdown
Contributor

Thx :-)

@potiuk

Copy link
Copy Markdown
Member

Thx :-)

yep. Feature flag nicely implemented here to start with and I will let @mhenc to explore switching to the new serializer #30560

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIP-44Airflow Internal APIarea:serializationchangelog:skipChanges that should be skipped from the changelog (CI, tests, etc..)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AIP-44 Implement conversion to Pydantic-ORM objects in Internal API

7 participants

@mhenc@potiuk@ashb@bolkedebruin@uranusjr@vincbeck@ephraimbuddy
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Support serialization to Pydantic models in Internal API - #30282

Merged
potiuk merged 2 commits into
apache:mainfrom
mhenc:pydantic_internal
Apr 5, 2023
Merged

Support serialization to Pydantic models in Internal API#30282
potiuk merged 2 commits into
apache:mainfrom
mhenc:pydantic_internal

Conversation

@mhenc

Copy link
Copy Markdown
Contributor

Follow-up for #29776

With Pydantic types added to Airflow and changes to LocalTask Job in #30255 we can use serialize TaskInstance/DagRun/DagSet to Pydantic object to be used on client side.

closes: #30240

@mhenc
mhenc marked this pull request as ready for review March 24, 2023 14:11
@mhenc
mhenc requested review from ashb and kaxil as code ownersMarch 24, 2023 14:11
@mhenc

mhenc commented Mar 24, 2023

Copy link
Copy Markdown
ContributorAuthor

cc: @potiuk@vincbeck

@potiukpotiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good.

@potiuk

Copy link
Copy Markdown
Member

I think it would be great to add some unit tests though.

@mhenc

mhenc commented Mar 24, 2023

Copy link
Copy Markdown
ContributorAuthor

Added support for BaseJob and unit tests

@mhenc
mhenc requested a review from potiukMarch 24, 2023 15:01

@vincbeckvincbeck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@ashb

ashb commented Mar 25, 2023

Copy link
Copy Markdown
Member

/cc @bolkedebruin who has been overhauling the serde code for 2.6

@ashb
ashb requested a review from bolkedebruinMarch 25, 2023 09:26

@potiukpotiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@bolkedebruin -> any comments?

A small general comment as I know from offline discussions I know you have reservation to the way AIP-44 in general - even if it is approaved and way in-progress.

I think those changes we do nownicely plugs in SQLAlchemy models into our serialization with super-small cost and maintenance effort needed (as described in the original Pydantic PR #29776 - almost no overhead of code to maintain and nicely piggybacks on battle proven Pydantic - used by very serious projects - wih SQLALchemy and ORM model as the first-class citizen).

I think if we implement it now and follow through with Internal API implementation (for quite a while we will mark it as experimental, I am sure) and my bet is the work we are doing will allow to nicely decouple the DB from the actual code that is run in the worker. Even if we (much) later decide to implement another solution (workload based for example), those changes will not hold us back, but rather make it easier to understand which parts of the process we need to replace in order to make this happen.

I think our changes are specifically aimed in making minimal "surgical" changes to existing code to make also separation-of-concerns better, and then any future discussions might get easier once we complete it.

I think we are not ready to spend time on making more "Architectural" changes now. And I also think what we implement now will make it easier, not harder if we decide to them (for Airflow 3 for example).

I honestly think this is a good way to move it forward :).

@potiuk

Copy link
Copy Markdown
Member

Hey @bolkedebruin - any comments ? I think it nicely (and optionally) plugs in our serialization to add more capabilities we need in AIP-44 so if there will be no more feedback, I am planning to merge that one so that we can proceed.

Comment threadairflow/serialization/serialized_objects.py Outdated
@potiuk

Copy link
Copy Markdown
Member

I assume no news is a good news and merge this one once it passes (I rebased to apply fix to pytest collection timeout from today)., @uranusjr -> maybe alse we could start merging the decoupling:

#30255 -> #30302 -> #30308 -> #30376

It starts to hold us back quite a lot and I would love to progress with AIP-44 implementation.

@potiuk

Copy link
Copy Markdown
Member

Looks good. Merging. I decided also to move the Pydantic classes to serialization as suggested by @uranusjr as immediate follow-up. Any conflicts there will be super-easy to solve as those will be only imports - In my refactoring, I barely touch those classes now after removing globals stuff recently.

@potiuk

Copy link
Copy Markdown
Member

Though - I see this PR has fallen victim of the "UI Rebase bug" from GitHub @mhenc can you please re-push your branch after manual rebase?

@potiuk
potiuk merged commit 41c8e58 into apache:mainApr 5, 2023
@mhenc
mhenc deleted the pydantic_internal branch April 5, 2023 13:39
@bolkedebruin

bolkedebruin commented Apr 6, 2023

Copy link
Copy Markdown
Contributor

If someone can tell me how to setup gmail filters so these notifications get somewhere visible I'd appreciate it :/. My comment would be why this is tied to the old serialization? I understand it is merged of course, because I think earlier (other PR related to this AIP) we agreed upon not extending the old serializer.

@potiuk

Copy link
Copy Markdown
Member

Where should we add it ? - we can still move it (I have not followed the serialisation discussion earlier but I am eager to learn :).

I would suggest to add "@bolkedebruin" in "contains word" and make sure it is flagged as important, not skip inbox etc.

@bolkedebruin

Copy link
Copy Markdown
Contributor

Thanks, I'll try that.

In an earlier discussion @mhenc added some functionality to the old serializer on the basis of that rebasing on the current serializer, which supports versioning, is an order of magnitude faster, and is more flexible and maintainable, was too much impact. I agreed on the condition (i think explicitly) that we then wouldn't add more functionality to the old serializer. However, I don't consider this a small change anymore. So, I wonder what the reasoning was and maybe the suggestion is to at least provide the same functionality in the new serializer if we really need this now.

@potiuk

potiuk commented Apr 6, 2023

Copy link
Copy Markdown
Member

What's the new vs. old serialization @bolkedebruin?

Sorry I have not paid too much attention. I looked through the code now - do I understand correctly (correct me if I am wrong) that the change is to separate serializer "type"s into separate modules in the "serializer" package and we register them dynamically in serde._register() - discovering the different "serializers" we have there ? In this case we would then have "pydantic.py" module in "serializers" and use "serde.serialize/deserialize" to serialize such objects instead of BaseSerialization.serialize/deserialize?

That sounds very reasonable approach IMHO - and I like it a lot more than the if/elif approach in the BaseSerializer (if I correctly understand it).

So @mhenc - is there a reason why we would not be able to do that? Because if that's the future direcrion of our serialization then I'd be in favour of doing so (unless there are some resons we would not like/or couldn't do it). I think we are anyhow heading now for 2.7 with AIP-44, so even if it means a bit more refactoring and testing, that would make more sense.

@bolkedebruin

Copy link
Copy Markdown
Contributor

@potiuk Yes, you are generally correct. In @mhenc defense there could be reasons to not integrate with the new serializer yet, basically if you rely on DAG serialization which I haven't completed yet. Yet, extending the old serialization significantly seems odd.

@potiuk

potiuk commented Apr 6, 2023

Copy link
Copy Markdown
Member

@potiuk Yes, you are generally correct. In @mhenc defense there could be reasons to not integrate with the new serializer yet, basically if you rely on DAG serialization which I haven't completed yet. Yet, extending the old serialization significantly seems odd.

I think we can remove that part for now since we are anyhow moving it behind a feature flag as 2.6.0 is going to happen before we manage to merge outstanding changes and complete testing #30509#30510

@potiuk

Copy link
Copy Markdown
Member

Once we merge #30509#30510 we can put it behind AIP-44 feature flag and we can swap it out when the new serialization is ready.

@mhenc

mhenc commented Apr 7, 2023

Copy link
Copy Markdown
ContributorAuthor

Yes, I still plan to integrate with new serialization, this PR was just to unblock any work with AIP-44.
I remember when we talked about that a while ago it was still under development.
Let me check if we rely on DAG Serialization (I think we don't). So I can work now on replacing the serialization framework for AIP-44.

@potiuk

potiuk commented Apr 7, 2023

Copy link
Copy Markdown
Member

Yeah. You can start with putting the change here behind _ENABLE_AIP_44 feature flag, so that we know this part is not used, until we replace it with the "new" serialization (and we can leave TODO: comment to remove it once we switch to the new one).

@ephraimbuddyephraimbuddy added changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) AIP-44 Airflow Internal API labels Apr 11, 2023
@bolkedebruin

Copy link
Copy Markdown
Contributor

Thx :-)

@potiuk

Copy link
Copy Markdown
Member

Thx :-)

yep. Feature flag nicely implemented here to start with and I will let @mhenc to explore switching to the new serializer #30560

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIP-44Airflow Internal APIarea:serializationchangelog:skipChanges that should be skipped from the changelog (CI, tests, etc..)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AIP-44 Implement conversion to Pydantic-ORM objects in Internal API

7 participants

@mhenc@potiuk@ashb@bolkedebruin@uranusjr@vincbeck@ephraimbuddy
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Support serialization to Pydantic models in Internal API - #30282

Merged
potiuk merged 2 commits into
apache:mainfrom
mhenc:pydantic_internal
Apr 5, 2023
Merged

Support serialization to Pydantic models in Internal API#30282
potiuk merged 2 commits into
apache:mainfrom
mhenc:pydantic_internal

Conversation

@mhenc

Copy link
Copy Markdown
Contributor

Follow-up for #29776

With Pydantic types added to Airflow and changes to LocalTask Job in #30255 we can use serialize TaskInstance/DagRun/DagSet to Pydantic object to be used on client side.

closes: #30240

@mhenc
mhenc marked this pull request as ready for review March 24, 2023 14:11
@mhenc
mhenc requested review from ashb and kaxil as code ownersMarch 24, 2023 14:11
@mhenc

mhenc commented Mar 24, 2023

Copy link
Copy Markdown
ContributorAuthor

cc: @potiuk@vincbeck

@potiukpotiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good.

@potiuk

Copy link
Copy Markdown
Member

I think it would be great to add some unit tests though.

@mhenc

mhenc commented Mar 24, 2023

Copy link
Copy Markdown
ContributorAuthor

Added support for BaseJob and unit tests

@mhenc
mhenc requested a review from potiukMarch 24, 2023 15:01

@vincbeckvincbeck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@ashb

ashb commented Mar 25, 2023

Copy link
Copy Markdown
Member

/cc @bolkedebruin who has been overhauling the serde code for 2.6

@ashb
ashb requested a review from bolkedebruinMarch 25, 2023 09:26

@potiukpotiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@bolkedebruin -> any comments?

A small general comment as I know from offline discussions I know you have reservation to the way AIP-44 in general - even if it is approaved and way in-progress.

I think those changes we do nownicely plugs in SQLAlchemy models into our serialization with super-small cost and maintenance effort needed (as described in the original Pydantic PR #29776 - almost no overhead of code to maintain and nicely piggybacks on battle proven Pydantic - used by very serious projects - wih SQLALchemy and ORM model as the first-class citizen).

I think if we implement it now and follow through with Internal API implementation (for quite a while we will mark it as experimental, I am sure) and my bet is the work we are doing will allow to nicely decouple the DB from the actual code that is run in the worker. Even if we (much) later decide to implement another solution (workload based for example), those changes will not hold us back, but rather make it easier to understand which parts of the process we need to replace in order to make this happen.

I think our changes are specifically aimed in making minimal "surgical" changes to existing code to make also separation-of-concerns better, and then any future discussions might get easier once we complete it.

I think we are not ready to spend time on making more "Architectural" changes now. And I also think what we implement now will make it easier, not harder if we decide to them (for Airflow 3 for example).

I honestly think this is a good way to move it forward :).

@potiuk

Copy link
Copy Markdown
Member

Hey @bolkedebruin - any comments ? I think it nicely (and optionally) plugs in our serialization to add more capabilities we need in AIP-44 so if there will be no more feedback, I am planning to merge that one so that we can proceed.

Comment threadairflow/serialization/serialized_objects.py Outdated
@potiuk

Copy link
Copy Markdown
Member

I assume no news is a good news and merge this one once it passes (I rebased to apply fix to pytest collection timeout from today)., @uranusjr -> maybe alse we could start merging the decoupling:

#30255 -> #30302 -> #30308 -> #30376

It starts to hold us back quite a lot and I would love to progress with AIP-44 implementation.

@potiuk

Copy link
Copy Markdown
Member

Looks good. Merging. I decided also to move the Pydantic classes to serialization as suggested by @uranusjr as immediate follow-up. Any conflicts there will be super-easy to solve as those will be only imports - In my refactoring, I barely touch those classes now after removing globals stuff recently.

@potiuk

Copy link
Copy Markdown
Member

Though - I see this PR has fallen victim of the "UI Rebase bug" from GitHub @mhenc can you please re-push your branch after manual rebase?

@potiuk
potiuk merged commit 41c8e58 into apache:mainApr 5, 2023
@mhenc
mhenc deleted the pydantic_internal branch April 5, 2023 13:39
@bolkedebruin

bolkedebruin commented Apr 6, 2023

Copy link
Copy Markdown
Contributor

If someone can tell me how to setup gmail filters so these notifications get somewhere visible I'd appreciate it :/. My comment would be why this is tied to the old serialization? I understand it is merged of course, because I think earlier (other PR related to this AIP) we agreed upon not extending the old serializer.

@potiuk

Copy link
Copy Markdown
Member

Where should we add it ? - we can still move it (I have not followed the serialisation discussion earlier but I am eager to learn :).

I would suggest to add "@bolkedebruin" in "contains word" and make sure it is flagged as important, not skip inbox etc.

@bolkedebruin

Copy link
Copy Markdown
Contributor

Thanks, I'll try that.

In an earlier discussion @mhenc added some functionality to the old serializer on the basis of that rebasing on the current serializer, which supports versioning, is an order of magnitude faster, and is more flexible and maintainable, was too much impact. I agreed on the condition (i think explicitly) that we then wouldn't add more functionality to the old serializer. However, I don't consider this a small change anymore. So, I wonder what the reasoning was and maybe the suggestion is to at least provide the same functionality in the new serializer if we really need this now.

@potiuk

potiuk commented Apr 6, 2023

Copy link
Copy Markdown
Member

What's the new vs. old serialization @bolkedebruin?

Sorry I have not paid too much attention. I looked through the code now - do I understand correctly (correct me if I am wrong) that the change is to separate serializer "type"s into separate modules in the "serializer" package and we register them dynamically in serde._register() - discovering the different "serializers" we have there ? In this case we would then have "pydantic.py" module in "serializers" and use "serde.serialize/deserialize" to serialize such objects instead of BaseSerialization.serialize/deserialize?

That sounds very reasonable approach IMHO - and I like it a lot more than the if/elif approach in the BaseSerializer (if I correctly understand it).

So @mhenc - is there a reason why we would not be able to do that? Because if that's the future direcrion of our serialization then I'd be in favour of doing so (unless there are some resons we would not like/or couldn't do it). I think we are anyhow heading now for 2.7 with AIP-44, so even if it means a bit more refactoring and testing, that would make more sense.

@bolkedebruin

Copy link
Copy Markdown
Contributor

@potiuk Yes, you are generally correct. In @mhenc defense there could be reasons to not integrate with the new serializer yet, basically if you rely on DAG serialization which I haven't completed yet. Yet, extending the old serialization significantly seems odd.

@potiuk

potiuk commented Apr 6, 2023

Copy link
Copy Markdown
Member

@potiuk Yes, you are generally correct. In @mhenc defense there could be reasons to not integrate with the new serializer yet, basically if you rely on DAG serialization which I haven't completed yet. Yet, extending the old serialization significantly seems odd.

I think we can remove that part for now since we are anyhow moving it behind a feature flag as 2.6.0 is going to happen before we manage to merge outstanding changes and complete testing #30509#30510

@potiuk

Copy link
Copy Markdown
Member

Once we merge #30509#30510 we can put it behind AIP-44 feature flag and we can swap it out when the new serialization is ready.

@mhenc

mhenc commented Apr 7, 2023

Copy link
Copy Markdown
ContributorAuthor

Yes, I still plan to integrate with new serialization, this PR was just to unblock any work with AIP-44.
I remember when we talked about that a while ago it was still under development.
Let me check if we rely on DAG Serialization (I think we don't). So I can work now on replacing the serialization framework for AIP-44.

@potiuk

potiuk commented Apr 7, 2023

Copy link
Copy Markdown
Member

Yeah. You can start with putting the change here behind _ENABLE_AIP_44 feature flag, so that we know this part is not used, until we replace it with the "new" serialization (and we can leave TODO: comment to remove it once we switch to the new one).

@ephraimbuddyephraimbuddy added changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) AIP-44 Airflow Internal API labels Apr 11, 2023
@bolkedebruin

Copy link
Copy Markdown
Contributor

Thx :-)

@potiuk

Copy link
Copy Markdown
Member

Thx :-)

yep. Feature flag nicely implemented here to start with and I will let @mhenc to explore switching to the new serializer #30560

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIP-44Airflow Internal APIarea:serializationchangelog:skipChanges that should be skipped from the changelog (CI, tests, etc..)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AIP-44 Implement conversion to Pydantic-ORM objects in Internal API

7 participants

@mhenc@potiuk@ashb@bolkedebruin@uranusjr@vincbeck@ephraimbuddy
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Support serialization to Pydantic models in Internal API - #30282

Merged
potiuk merged 2 commits into
apache:mainfrom
mhenc:pydantic_internal
Apr 5, 2023
Merged

Support serialization to Pydantic models in Internal API#30282
potiuk merged 2 commits into
apache:mainfrom
mhenc:pydantic_internal

Conversation

@mhenc

Copy link
Copy Markdown
Contributor

Follow-up for #29776

With Pydantic types added to Airflow and changes to LocalTask Job in #30255 we can use serialize TaskInstance/DagRun/DagSet to Pydantic object to be used on client side.

closes: #30240

@mhenc
mhenc marked this pull request as ready for review March 24, 2023 14:11
@mhenc
mhenc requested review from ashb and kaxil as code ownersMarch 24, 2023 14:11
@mhenc

mhenc commented Mar 24, 2023

Copy link
Copy Markdown
ContributorAuthor

cc: @potiuk@vincbeck

@potiukpotiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good.

@potiuk

Copy link
Copy Markdown
Member

I think it would be great to add some unit tests though.

@mhenc

mhenc commented Mar 24, 2023

Copy link
Copy Markdown
ContributorAuthor

Added support for BaseJob and unit tests

@mhenc
mhenc requested a review from potiukMarch 24, 2023 15:01

@vincbeckvincbeck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@ashb

ashb commented Mar 25, 2023

Copy link
Copy Markdown
Member

/cc @bolkedebruin who has been overhauling the serde code for 2.6

@ashb
ashb requested a review from bolkedebruinMarch 25, 2023 09:26

@potiukpotiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@bolkedebruin -> any comments?

A small general comment as I know from offline discussions I know you have reservation to the way AIP-44 in general - even if it is approaved and way in-progress.

I think those changes we do nownicely plugs in SQLAlchemy models into our serialization with super-small cost and maintenance effort needed (as described in the original Pydantic PR #29776 - almost no overhead of code to maintain and nicely piggybacks on battle proven Pydantic - used by very serious projects - wih SQLALchemy and ORM model as the first-class citizen).

I think if we implement it now and follow through with Internal API implementation (for quite a while we will mark it as experimental, I am sure) and my bet is the work we are doing will allow to nicely decouple the DB from the actual code that is run in the worker. Even if we (much) later decide to implement another solution (workload based for example), those changes will not hold us back, but rather make it easier to understand which parts of the process we need to replace in order to make this happen.

I think our changes are specifically aimed in making minimal "surgical" changes to existing code to make also separation-of-concerns better, and then any future discussions might get easier once we complete it.

I think we are not ready to spend time on making more "Architectural" changes now. And I also think what we implement now will make it easier, not harder if we decide to them (for Airflow 3 for example).

I honestly think this is a good way to move it forward :).

@potiuk

Copy link
Copy Markdown
Member

Hey @bolkedebruin - any comments ? I think it nicely (and optionally) plugs in our serialization to add more capabilities we need in AIP-44 so if there will be no more feedback, I am planning to merge that one so that we can proceed.

Comment threadairflow/serialization/serialized_objects.py Outdated
@potiuk

Copy link
Copy Markdown
Member

I assume no news is a good news and merge this one once it passes (I rebased to apply fix to pytest collection timeout from today)., @uranusjr -> maybe alse we could start merging the decoupling:

#30255 -> #30302 -> #30308 -> #30376

It starts to hold us back quite a lot and I would love to progress with AIP-44 implementation.

@potiuk

Copy link
Copy Markdown
Member

Looks good. Merging. I decided also to move the Pydantic classes to serialization as suggested by @uranusjr as immediate follow-up. Any conflicts there will be super-easy to solve as those will be only imports - In my refactoring, I barely touch those classes now after removing globals stuff recently.

@potiuk

Copy link
Copy Markdown
Member

Though - I see this PR has fallen victim of the "UI Rebase bug" from GitHub @mhenc can you please re-push your branch after manual rebase?

@potiuk
potiuk merged commit 41c8e58 into apache:mainApr 5, 2023
@mhenc
mhenc deleted the pydantic_internal branch April 5, 2023 13:39
@bolkedebruin

bolkedebruin commented Apr 6, 2023

Copy link
Copy Markdown
Contributor

If someone can tell me how to setup gmail filters so these notifications get somewhere visible I'd appreciate it :/. My comment would be why this is tied to the old serialization? I understand it is merged of course, because I think earlier (other PR related to this AIP) we agreed upon not extending the old serializer.

@potiuk

Copy link
Copy Markdown
Member

Where should we add it ? - we can still move it (I have not followed the serialisation discussion earlier but I am eager to learn :).

I would suggest to add "@bolkedebruin" in "contains word" and make sure it is flagged as important, not skip inbox etc.

@bolkedebruin

Copy link
Copy Markdown
Contributor

Thanks, I'll try that.

In an earlier discussion @mhenc added some functionality to the old serializer on the basis of that rebasing on the current serializer, which supports versioning, is an order of magnitude faster, and is more flexible and maintainable, was too much impact. I agreed on the condition (i think explicitly) that we then wouldn't add more functionality to the old serializer. However, I don't consider this a small change anymore. So, I wonder what the reasoning was and maybe the suggestion is to at least provide the same functionality in the new serializer if we really need this now.

@potiuk

potiuk commented Apr 6, 2023

Copy link
Copy Markdown
Member

What's the new vs. old serialization @bolkedebruin?

Sorry I have not paid too much attention. I looked through the code now - do I understand correctly (correct me if I am wrong) that the change is to separate serializer "type"s into separate modules in the "serializer" package and we register them dynamically in serde._register() - discovering the different "serializers" we have there ? In this case we would then have "pydantic.py" module in "serializers" and use "serde.serialize/deserialize" to serialize such objects instead of BaseSerialization.serialize/deserialize?

That sounds very reasonable approach IMHO - and I like it a lot more than the if/elif approach in the BaseSerializer (if I correctly understand it).

So @mhenc - is there a reason why we would not be able to do that? Because if that's the future direcrion of our serialization then I'd be in favour of doing so (unless there are some resons we would not like/or couldn't do it). I think we are anyhow heading now for 2.7 with AIP-44, so even if it means a bit more refactoring and testing, that would make more sense.

@bolkedebruin

Copy link
Copy Markdown
Contributor

@potiuk Yes, you are generally correct. In @mhenc defense there could be reasons to not integrate with the new serializer yet, basically if you rely on DAG serialization which I haven't completed yet. Yet, extending the old serialization significantly seems odd.

@potiuk

potiuk commented Apr 6, 2023

Copy link
Copy Markdown
Member

@potiuk Yes, you are generally correct. In @mhenc defense there could be reasons to not integrate with the new serializer yet, basically if you rely on DAG serialization which I haven't completed yet. Yet, extending the old serialization significantly seems odd.

I think we can remove that part for now since we are anyhow moving it behind a feature flag as 2.6.0 is going to happen before we manage to merge outstanding changes and complete testing #30509#30510

@potiuk

Copy link
Copy Markdown
Member

Once we merge #30509#30510 we can put it behind AIP-44 feature flag and we can swap it out when the new serialization is ready.

@mhenc

mhenc commented Apr 7, 2023

Copy link
Copy Markdown
ContributorAuthor

Yes, I still plan to integrate with new serialization, this PR was just to unblock any work with AIP-44.
I remember when we talked about that a while ago it was still under development.
Let me check if we rely on DAG Serialization (I think we don't). So I can work now on replacing the serialization framework for AIP-44.

@potiuk

potiuk commented Apr 7, 2023

Copy link
Copy Markdown
Member

Yeah. You can start with putting the change here behind _ENABLE_AIP_44 feature flag, so that we know this part is not used, until we replace it with the "new" serialization (and we can leave TODO: comment to remove it once we switch to the new one).

@ephraimbuddyephraimbuddy added changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) AIP-44 Airflow Internal API labels Apr 11, 2023
@bolkedebruin

Copy link
Copy Markdown
Contributor

Thx :-)

@potiuk

Copy link
Copy Markdown
Member

Thx :-)

yep. Feature flag nicely implemented here to start with and I will let @mhenc to explore switching to the new serializer #30560

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIP-44Airflow Internal APIarea:serializationchangelog:skipChanges that should be skipped from the changelog (CI, tests, etc..)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AIP-44 Implement conversion to Pydantic-ORM objects in Internal API

7 participants

@mhenc@potiuk@ashb@bolkedebruin@uranusjr@vincbeck@ephraimbuddy