Skip to content

refactor: Vendoring Protobuf #1869

Open
gavin-aguiar wants to merge 9 commits into
devfrom
gaaguiar/proto_fix
Open

refactor: Vendoring Protobuf #1869
gavin-aguiar wants to merge 9 commits into
devfrom
gaaguiar/proto_fix

Conversation

@gavin-aguiar
Copy link
Copy Markdown
Contributor

Description

Fixes #


Pull Request Checklist

Host-Worker Contract

  • Does this PR impact the host-worker contract (e.g., gRPC messages, shared interfaces)?
    • If yes, have the changes been applied to:
      • azure_functions_worker (Python <= 3.12)
      • proxy_worker (Python >= 3.13)
    • If no, please explain why:

Worker Execution Logic

  • Does this PR affect worker execution logic (e.g., function invocation, bindings, lifecycle)?
    If yes, please answer the following:

Python Version Coverage

  • Does this change apply to both Python <=3.12 and 3.13+?
  • If yes, have the changes been made to:
    • azure_functions_worker (Python <= 3.12)
    • runtimes/v1 / runtimes/v2 (Python >= 3.13)
  • If no, please explain why:

Programming Model Compatibility (for Python 3.13+)

  • Does this change apply to both:
    • V1 programming model (runtimes/v1)?
    • V2 programming model (runtimes/v2)?
  • Explanation (if limited to one model):

@gavin-aguiar gavin-aguiar marked this pull request as ready for review June 2, 2026 17:30


def _build_rewriter(top_level_names: Iterable[str]):
"""Build a per-file rewriter for the given top-level package names.
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.

Is this used when rewriting protobuf imports inside the worker? Or is it rewriting the protobuf imports within the protobuf module itself?

init.write_text(
"# Copyright (c) Microsoft Corporation. All rights reserved.\n"
"# Licensed under the MIT License.\n"
"# Vendored namespace package. See ../README.md.\n",
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.

Can you update the README / some other documentation with this change?

# pure-Python implementation here so that any vendored protobuf module
# imported transitively never tries to load a C extension. This must run
# before any submodule import that touches protobuf.
os.environ.setdefault("PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION", "python")
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.

Are we setting this variable by default for production environments? We only need this setting when performing the build, right? We can add this as a pipeline variable instead

# assigned onto a vendored field (e.g. ``RpcRetryOptions.delay_interval``)
# must therefore come from the same vendored protobuf — a ``Duration``
# imported from the customer-facing ``google.protobuf`` namespace lives in
# a different descriptor pool and the assignment would fail at runtime.
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.

nit: lengthy comment. We can just say that the worker no longer imports from google.protobuf directly now & references _vendored.google.protobuf now

# to the worker's vendored copy, not whatever the customer ships in
# their `.python_packages`. The proxy worker (Python 3.13+) runs out
# of process and is unaffected, so we only rewrite for the in-process
# worker.
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.

nit: proxy worker is unaffected for a different reason & azure functions worker is not "in-proc"

# their `.python_packages`. The proxy worker (Python 3.13+) runs out
# of process and is unaffected, so we only rewrite for the in-process
# worker.
rewrite_protobuf = WORKER_DIR == "azure_functions_worker"
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.

Should this be a global variable, similar to WORKER_DIR?

regardless of any version the customer ships in ``.python_packages``.
Safe to re-run; the script is idempotent.

Skipped for the proxy worker (Python >= 3.13) which is out-of-process
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.

nit: out-of-process is not the reason 3.13 is unaffected

if WORKER_DIR != "azure_functions_worker":
print(
f"Skipping vendor_deps for {WORKER_DIR} "
"(only required for in-process worker)."
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.

nit: not in-process

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.

2 participants