Skip to content

Store query expression files relative to the current directory - #4811

Merged
josevalim merged 2 commits into
elixir-ecto:masterfrom
onnimonni:relative-query-file
Nov 1, 2026
Merged

josevalim merged 2 commits into
elixir-ecto:masterfrom
onnimonni:relative-query-file

Conversation

@onnimonni

Copy link
Copy Markdown
Contributor

Query expressions (QueryExpr, BooleanExpr, JoinExpr, FromExpr, ...) store the caller's file at compile time; it is shown in Ecto.QueryError messages. It was the absolute path, so a copy of a project that reuses its _build reported the original checkout's files. Examples of such copies: git worktrees for parallel coding agents, copy-on-write clones, restored CI caches (see phoenixframework/phoenix#6855).

This adds Ecto.Query.Builder.file/1, which stores the file relative to the current directory when the file is inside it. That matches Elixir's own stacktraces and diagnostics. All 28 env.file uses in the query builders now go through it. Files outside the project stay absolute. Exception.format_file_line/2 prints relative paths fine.

With this change, the only remaining absolute paths in a generated Phoenix app's compiled modules (with the related Phoenix/LiveView PRs) are compile metadata (:source, debug info). Queries were the last place where the path ended up in literals.

Test: a new test in query_test.exs checks that from, where, select and order_by store the relative file. It fails on master. Full suite: 1617 passed.

Query expressions store the caller's file for error messages. With an
absolute path, a copy of the project that reuses its build (git worktree,
copy-on-write clone) reported the original checkout's files. Elixir's own
stacktraces and diagnostics are relative to the current directory too.
@josevalim

Copy link
Copy Markdown
Member

@onnimonni fantastic work throughout, thank you!!!

@josevalim
josevalim merged commit c8091a1 into elixir-ecto:master Nov 1, 2026
8 checks passed
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

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