Skip to content

Use dynamic inspection to find django entry points#15367

Merged
msullivan merged 14 commits intomainfrom
django-dynamic
Mar 6, 2026
Merged

Use dynamic inspection to find django entry points#15367
msullivan merged 14 commits intomainfrom
django-dynamic

Conversation

@msullivan
Copy link
Contributor

@msullivan msullivan commented Mar 4, 2026

Instead of parsing the manage.py and the settings file,
we instead import it with python and print out the globals in it.

To find the settings file, we run manage.py with a monkeypatch.

This will handle some stuff like sibling imports (from .common import *, discussed in #15354) that we don't handle now, and will provide a
framework for handling other dynamic stuff as well.

I've pulled out some of the existing django identification stuff.

Note

Low Risk Change

This PR replaces static AST-based Django settings parsing with dynamic Python execution that imports and runs manage.py, which introduces potential code execution risks during build but is a refactor of existing build-time behavior rather than a security control change.

  • New dynamic Django settings discovery executes Python code via execa('python', ['-c', script])
  • Removes static AST parsing functions (parseDjangoSettingsModule, getDjangoEntrypoint) in favor of runtime imports
  • Adds Python script that monkeypatches Django and runs manage.py to extract settings

Risk assessment for commit 41ffba8.

@changeset-bot
Copy link

changeset-bot bot commented Mar 4, 2026

🦋 Changeset detected

Latest commit: 41ffba8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
@vercel/python-analysis Minor
@vercel/build-utils Minor
@vercel/python Minor
@vercel/backends Patch
vercel Patch
@vercel/client Patch
@vercel/elysia Patch
@vercel/express Patch
@vercel/fastify Patch
@vercel/gatsby-plugin-vercel-builder Patch
@vercel/h3 Patch
@vercel/hono Patch
@vercel/koa Patch
@vercel/nestjs Patch
@vercel/node Patch
@vercel/static-build Patch
@vercel/cervel Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

🧪 Unit Test Strategy

Comparing: 0a7889241ffba8 (view diff)

Strategy: Code changed outside of a package - running all unit tests

⚠️ All unit tests will run because global code changes could impact all packages.

Affected packages - 40 (100%)
  1. @vercel-internals/get-package-json
  2. @vercel/backends
  3. @vercel/build-utils
  4. @vercel/cervel
  5. @vercel/cli-auth
  6. @vercel/client
  7. @vercel/config
  8. @vercel/detect-agent
  9. @vercel/edge
  10. @vercel/elysia
  11. @vercel/error-utils
  12. @vercel/express
  13. @vercel/fastify
  14. @vercel/firewall
  15. @vercel/frameworks
  16. @vercel/fs-detectors
  17. @vercel/functions
  18. @vercel/gatsby-plugin-vercel-builder
  19. @vercel/go
  20. @vercel/h3
  21. @vercel/hono
  22. @vercel/hydrogen
  23. @vercel/koa
  24. @vercel/nestjs
  25. @vercel/next
  26. @vercel/node
  27. @vercel/oidc
  28. @vercel/oidc-aws-credentials-provider
  29. @vercel/python
  30. @vercel/python-analysis
  31. @vercel/redwood
  32. @vercel/related-projects
  33. @vercel/remix-builder
  34. @vercel/routing-utils
  35. @vercel/ruby
  36. @vercel/rust
  37. @vercel/static-build
  38. @vercel/static-config
  39. examples
  40. vercel

Results

  • Unit tests: All affected packages will run unit tests
  • E2E tests: Running in parallel via E2E Tests workflow
  • Type checks: All affected packages will run type checks

This comment is automatically generated based on the affected testing strategy

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

📦 CLI Tarball Ready

The Vercel CLI tarball for this PR is now available!

Quick Test

You can test this PR's CLI directly by running:

npx https://vercel-jpypo3686.vercel.sh/tarballs/vercel.tgz --help

Use in vercel.json

To use this CLI version in your project builds, add to your vercel.json:

{
  "build": {
    "env": {
      "VERCEL_CLI_VERSION": "vercel@https://vercel-jpypo3686.vercel.sh/tarballs/vercel.tgz"
    }
  }
}

Python Runtime Wheel

A vercel-runtime wheel was also built for this PR.
To use in your Python project builds, also set this environment variable:

VERCEL_RUNTIME_PYTHON="vercel-runtime @ https://vercel-jpypo3686.vercel.sh/tarballs/vercel_runtime-0.6.0.dev1772758568+41ffba8-py3-none-any.whl"

Python Workers Wheel

A vercel-workers wheel was also built for this PR.
To use in your Python project builds, also set this environment variable:

VERCEL_WORKERS_PYTHON="vercel-workers @ https://vercel-jpypo3686.vercel.sh/tarballs/vercel_workers-0.1.0.dev1772758568+41ffba8-py3-none-any.whl"

@msullivan msullivan changed the title [WIP] Use dynamic inspection to find django entry points Use dynamic inspection to find django entry points Mar 5, 2026
@msullivan msullivan marked this pull request as ready for review March 5, 2026 03:50
@msullivan msullivan requested review from a team as code owners March 5, 2026 03:50
msullivan and others added 10 commits March 5, 2026 10:27
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Instead of statically parsing manage.py with WASM AST to extract the
DJANGO_SETTINGS_MODULE value, run manage.py itself with a patched
execute_from_command_line to capture the actual settings module from
the environment, then load and dump settings in one Python invocation.

This handles any way manage.py might set DJANGO_SETTINGS_MODULE
(conditionals, variables, etc.), not just os.environ.setdefault.

Also removes the now-dead parseDjangoSettingsModule from all layers
(WIT, Rust, TypeScript wrapper, re-exports, and tests).
Move the inline Python script from django.ts into
vc_django_settings.py, matching the pattern used by vc_init_dev.py.
Read it at module load time and pass via python -c to keep sys.path[0]
as the project directory.
Move vc_django_settings.py and vc_init_dev.py into a templates/
subdirectory for better organization.
The templates/ directory containing vc_django_settings.py and
vc_init_dev.py was not included in the published package, causing
ENOENT at import time in CI.
Resolve conflicts keeping containsTopLevelCallable and getStringConstant
from main while still removing parseDjangoSettingsModule (replaced by
dynamic manage.py execution)
@msullivan msullivan merged commit 921314f into main Mar 6, 2026
256 of 258 checks passed
@msullivan msullivan deleted the django-dynamic branch March 6, 2026 05:25
ztanner pushed a commit that referenced this pull request Mar 9, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @vercel/build-utils@13.7.0

### Minor Changes

- [python] add support for module-based entrypoints for cron jobs
([#15393](#15393))

- For the django frontend, dynamically load settings.py instead of
parsing it ([#15367](#15367))

### Patch Changes

- Updated dependencies
\[[`83e804013528fc54de31082960ae31f58339bd71`](83e8040),
[`921314f958c4ec85adb09e020310a5becb7f866c`](921314f)]:
    -   @vercel/python-analysis@0.9.0

## vercel@50.29.0

### Minor Changes

- Add interactive mode to `webhooks create` and change warning prefix
from `WARN!` to `WARNING!`
([#15406](#15406))

### Patch Changes

- Updated dependencies
\[[`32e8ba5f593fdeddeb63d241d7806d6c12fffe76`](32e8ba5),
[`83e804013528fc54de31082960ae31f58339bd71`](83e8040),
[`0f1fa86770a35d0192d64d36cb46d932e1d2a12a`](0f1fa86),
[`813f3d324404237e3806530b465625ea33816370`](813f3d3),
[`0a78892b1e155eb4b587a8b84c4e6814f750697f`](0a78892),
[`9a973a704b7350e19d0c3ac8e110ce55eea795b2`](9a973a7),
[`c6f5ac6c11fb7f431b5fb634a7fb321b10c829af`](c6f5ac6),
[`921314f958c4ec85adb09e020310a5becb7f866c`](921314f)]:
    -   @vercel/next@4.15.42
    -   @vercel/build-utils@13.7.0
    -   @vercel/python@6.21.0
    -   @vercel/detect-agent@1.1.1
    -   @vercel/static-build@2.8.46
    -   @vercel/backends@0.0.42
    -   @vercel/elysia@0.1.45
    -   @vercel/express@0.1.54
    -   @vercel/fastify@0.1.48
    -   @vercel/go@3.4.3
    -   @vercel/h3@0.1.54
    -   @vercel/hono@0.2.48
    -   @vercel/hydrogen@1.3.5
    -   @vercel/koa@0.1.28
    -   @vercel/nestjs@0.2.49
    -   @vercel/node@5.6.12
    -   @vercel/redwood@2.4.9
    -   @vercel/remix-builder@5.6.0
    -   @vercel/ruby@2.3.2
    -   @vercel/rust@1.0.5

## @vercel/fs-detectors@5.9.0

### Minor Changes

- [python] add support for module-based entrypoints for cron jobs
([#15393](#15393))

### Patch Changes

- [python] add support for Python worker services with Django tasks
([#15396](#15396))

## @vercel/python@6.21.0

### Minor Changes

- [python] add support for module-based entrypoints for cron jobs
([#15393](#15393))

- Avoid doing entry point detection on every request to a python dev
server ([#15365](#15365))

- For the django frontend, dynamically load settings.py instead of
parsing it ([#15367](#15367))

### Patch Changes

- speed up python entrypoint detection
([#15402](#15402))

- Add Python builder cache preparation for Build Output API v3 cache
globs, the builder virtualenv, and the repo-local uv cache.
([#15407](#15407))

- Updated dependencies
\[[`83e804013528fc54de31082960ae31f58339bd71`](83e8040),
[`921314f958c4ec85adb09e020310a5becb7f866c`](921314f)]:
    -   @vercel/python-analysis@0.9.0

## @vercel/python-analysis@0.9.0

### Minor Changes

- [python] add support for module-based entrypoints for cron jobs
([#15393](#15393))

- For the django frontend, dynamically load settings.py instead of
parsing it ([#15367](#15367))

## @vercel/backends@0.0.42

### Patch Changes

- Updated dependencies
\[[`83e804013528fc54de31082960ae31f58339bd71`](83e8040),
[`921314f958c4ec85adb09e020310a5becb7f866c`](921314f)]:
    -   @vercel/build-utils@13.7.0

## @vercel/cervel@0.0.29

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/backends@0.0.42

## @vercel/client@17.2.54

### Patch Changes

- Updated dependencies
\[[`83e804013528fc54de31082960ae31f58339bd71`](83e8040),
[`921314f958c4ec85adb09e020310a5becb7f866c`](921314f)]:
    -   @vercel/build-utils@13.7.0

## @vercel/config@0.0.38

### Patch Changes

- Fix type generation
([#15386](#15386))

## @vercel/detect-agent@1.1.1

### Patch Changes

- Add Antigravity agent detection via `ANTIGRAVITY_AGENT` environment
variable ([#15413](#15413))

- Detect Codex when `CODEX_CI` or `CODEX_THREAD_ID` is present.
([#15412](#15412))

## @vercel/elysia@0.1.45

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.6.12

## @vercel/express@0.1.54

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.6.12
    -   @vercel/cervel@0.0.29

## @vercel/fastify@0.1.48

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.6.12

## @vercel/gatsby-plugin-vercel-builder@2.0.144

### Patch Changes

- Updated dependencies
\[[`83e804013528fc54de31082960ae31f58339bd71`](83e8040),
[`921314f958c4ec85adb09e020310a5becb7f866c`](921314f)]:
    -   @vercel/build-utils@13.7.0

## @vercel/h3@0.1.54

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.6.12

## @vercel/hono@0.2.48

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.6.12

## @vercel/koa@0.1.28

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.6.12

## @vercel/nestjs@0.2.49

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.6.12

## @vercel/next@4.15.42

### Patch Changes

- Revert "[next] vary fallback allowQuery for partial fallback shells"
([#15418](#15418))

## @vercel/node@5.6.12

### Patch Changes

- Updated dependencies
\[[`83e804013528fc54de31082960ae31f58339bd71`](83e8040),
[`921314f958c4ec85adb09e020310a5becb7f866c`](921314f)]:
    -   @vercel/build-utils@13.7.0

## @vercel/static-build@2.8.46

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/gatsby-plugin-vercel-builder@2.0.144

## @vercel/python-runtime@0.6.0

### Minor Changes

- [python] add support for Python worker services with Django tasks
([#15396](#15396))

- [python] add support for module-based entrypoints for cron jobs
([#15393](#15393))


<!-- VADE_RISK_START -->
> [!NOTE]
> Low Risk Change
>
> This PR is an automated Changesets release that only updates version
numbers in package.json files, CHANGELOG.md files, and deletes changeset
markdown files — no functional code changes.
> 
> - Version bumps across ~30 packages (patch/minor)
> - Changelog and changeset file updates only
> - Single constant update: VERCEL_RUNTIME_VERSION = '0.6.0'
>
> <sup>Risk assessment for [commit
d3cf7ea](https://github.com/vercel/vercel/commit/d3cf7ea8deab73a058f4228f0346317fcf3e3dbc).</sup>
<!-- VADE_RISK_END -->

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

4 participants