Skip to content

Conversation

@ryanking13
Copy link
Contributor

Related: #5678

We would like to make a small breaking change in Python, but it seems like currently importing compat flags are only available in the JS code for Python workers.

This PR enables importing compat flags from python code of Python workers such as

import _cloudflare_compat_flags
_cloudflare_compat_flags.python_workflows

This PR includes updating the custom serializer for the snapshot as the compat flag object is exposed as a global object.

@ryanking13 ryanking13 requested review from a team as code owners December 17, 2025 09:27
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 17, 2025

CodSpeed Performance Report

Merging #5713 will not alter performance

Comparing python-compat-flag (1a46099) with main (177fb2f)

Summary

✅ 140 untouched
⏩ 38 skipped1

Footnotes

  1. 38 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@ryanking13 ryanking13 requested a review from hoodmane December 18, 2025 04:08
@ryanking13 ryanking13 force-pushed the python-compat-flag branch 2 times, most recently from 3fe54f1 to 1152c07 Compare January 2, 2026 06:12
Copy link
Contributor

@dom96 dom96 left a comment

Choose a reason for hiding this comment

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

Code changes look good.

One question I have is how does this interact with our baseline snapshots? We have to be careful to not serialise the compat flags in that snapshot as it could then cause issues.

| { cloudflare_compat_flags: true }
| SerializedJsModule;
/**
* Global objects that we need a custom serializer
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Global objects that we need a custom serializer
* Global objects that we need a custom serializer for

Copy link
Contributor

Choose a reason for hiding this comment

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

What about "Global objects that need a custom serializer"

get_pyodide_entrypoint_helper()
);

pyodide.registerJsModule('_cloudflare_compat_flags', COMPATIBILITY_FLAGS);
Copy link
Contributor

Choose a reason for hiding this comment

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

bike-shedding but maybe this should be _cf_private.compat_flags just to future proof a bit, so that if we get more of these private modules, they have a nice home

@ryanking13
Copy link
Contributor Author

One question I have is how does this interact with our baseline snapshots? We have to be careful to not serialise the compat flags in that snapshot as it could then cause issues.

What I thought was that because this uses a custom serializer, the compat flags will pick up the fresh, user-passed flags when deserializing the snapshot. @hoodmane Could you confirm that I am understanding it correctly?

@hoodmane
Copy link
Contributor

hoodmane commented Jan 2, 2026

That's right. Though if you say a = compat_flags.foo then obviously that is not going to be updated.

Copy link
Contributor

@hoodmane hoodmane left a comment

Choose a reason for hiding this comment

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

Looks good to me.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants