Skip to content

Support module plugs with options in pipe_through#6755

Merged
josevalim merged 1 commit into
phoenixframework:mainfrom
RicardoSantos-99:fix/6711-pipe-through-module-plug
Jul 20, 2026
Merged

Support module plugs with options in pipe_through#6755
josevalim merged 1 commit into
phoenixframework:mainfrom
RicardoSantos-99:fix/6711-pipe-through-module-plug

Conversation

@RicardoSantos-99

Copy link
Copy Markdown
Contributor

Closes #6711.

Using a module plug with options as a {plug, opts} tuple in pipe_through
raised at compile time:

pipe_through [:api, {MyPlug, greeting: "hey"}]

** (ArgumentError) errors were found at the given arguments:
  * 1st argument: not an atom

build_pipes/2 mapped every entry to {plug, [], true}, so a bare atom
(function plug, pipeline, or bare module plug) worked, but a {plug, opts}
tuple was passed through as the plug itself, which Plug.Builder then tried
to treat as an atom. This maps {plug, opts} tuples to {plug, opts, true}
and keeps the existing behaviour for bare entries.

Added a test covering the mixed case (a pipeline plus a module plug with
options) and documented the form in pipe_through/1.

Note: the route's pipe_through metadata (used by telemetry/logging) may now
contain a {plug, opts} tuple in addition to atoms. Happy to adjust if you'd
prefer that field to stay atoms-only.

A module plug given with options as a {plug, opts} tuple raised at
compile time:

    pipe_through [:api, {MyPlug, greeting: "hey"}]

    ** (ArgumentError) errors were found at the given arguments:
      * 1st argument: not an atom

build_pipes/2 mapped every entry to {plug, [], true}, so a bare atom
(function plug, pipeline, or module) worked, but a {plug, opts} tuple was
passed through as the plug itself, which Plug.Builder then tried to treat
as an atom. Map {plug, opts} tuples to {plug, opts, true} and keep the
existing behaviour for bare entries.

Closes phoenixframework#6711
@SteffenDE
SteffenDE requested a review from josevalim July 20, 2026 09:11
@josevalim

Copy link
Copy Markdown
Member

If we are going to support this approach, we need to traverse the list and make sure we don't add compile-time dependencies. In my opinion, it is preferrable for you to create a pipeline with the module plugs and call that instead, as the compile-time mechanism is already address there.

@josevalim

Copy link
Copy Markdown
Member

Ignore me, it seems we already support it, should we should support this and investigate the compile-time option after.

@josevalim
josevalim merged commit 12a0a0c into phoenixframework:main Jul 20, 2026
8 checks passed
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

@RicardoSantos-99
RicardoSantos-99 deleted the fix/6711-pipe-through-module-plug branch July 20, 2026 12:45
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.

pipe_through with module plug and options doesn't compile

2 participants