Skip to content

[python] Look for django entrypoint from setting file's from sibling imports.#15354

Closed
dnwpark wants to merge 2 commits intomainfrom
dnwpark/django-settings-import
Closed

[python] Look for django entrypoint from setting file's from sibling imports.#15354
dnwpark wants to merge 2 commits intomainfrom
dnwpark/django-settings-import

Conversation

@dnwpark
Copy link
Contributor

@dnwpark dnwpark commented Mar 3, 2026

A common pattern is:

hello/settings/dev.py:

from .common import *
...

hello/settings/common.py

...
WSGI_APPLICATION = hello.wsgi.application
...

Note

Low Risk Change

This PR adds a new feature to follow sibling imports when looking for Django entrypoints, consisting of new Rust parsing logic, TypeScript wrappers, and comprehensive tests with no security, auth, or schema changes.

  • New getStringConstantOrImport function in Rust/TS to follow sibling imports
  • Refactored getDjangoEntrypoint to check sibling settings files one level deep
  • Added 14 unit tests for new import-following logic

Risk assessment for commit 4153a3a.

@dnwpark dnwpark requested review from a team as code owners March 3, 2026 04:04
@changeset-bot
Copy link

changeset-bot bot commented Mar 3, 2026

🦋 Changeset detected

Latest commit: 4153a3a

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 Patch
@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

@dnwpark dnwpark changed the title [python] Read django settings from sibling importss. [python] Read django settings from sibling imports. Mar 3, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 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-mwamt7gto.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-mwamt7gto.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-mwamt7gto.vercel.sh/tarballs/vercel_runtime-0.6.0.dev1772510848+4153a3a-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-mwamt7gto.vercel.sh/tarballs/vercel_workers-0.1.0.dev1772510848+4153a3a-py3-none-any.whl"

@dnwpark dnwpark changed the title [python] Read django settings from sibling imports. [python] Look for django entrypoint from setting file's from sibling imports. Mar 3, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

🧪 Unit Test Strategy

Comparing: 91e36754153a3a (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

@msullivan
Copy link
Contributor

This code all looks totally fine but I'm not sure that we actually want to do it.

I think we are going to want to do dynamic analysis to recover the routes and stuff, and we might want to move the entrypoint detection into that when it is complicated. (I have something I'm working on that will start doing some dynamic analysis)

Copy link
Contributor

@msullivan msullivan left a comment

Choose a reason for hiding this comment

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

I think we should skip this and try a dynamic analysis instead

msullivan added a commit that referenced this pull request Mar 6, 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.



<!-- VADE_RISK_START -->
> [!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
>
> <sup>Risk assessment for [commit
41ffba8](https://github.com/vercel/vercel/commit/41ffba8d4062b6ec1d68cc450b422cf88732d46a).</sup>
<!-- VADE_RISK_END -->

---------

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
@dnwpark dnwpark closed this Mar 10, 2026
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