Skip to content

🐛 Materialize iterable middleware arguments before inspecting them - #617

Merged
MiWeiss merged 3 commits into
mainfrom
fix/iterable-middleware-arguments
Sep 3, 2026
Merged

🐛 Materialize iterable middleware arguments before inspecting them#617
MiWeiss merged 3 commits into
mainfrom
fix/iterable-middleware-arguments

Conversation

@MiWeiss

@MiWeiss MiWeiss commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

append_middleware/prepend_middleware are typed Iterable[Middleware], but the stack builders iterate the argument twice — once to compute middleware types for the duplicate warning, once to build the stack. A generator or other one-shot iterator is exhausted by the first pass, so the middleware is silently dropped.

import bibtexparser
from bibtexparser.middlewares import SeparateCoAuthors

bibtexparser.parse_string('@article{k, author={A and B}}', append_middleware=[SeparateCoAuthors()])
# ['A', 'B']  correct
bibtexparser.parse_string('@article{k, author={A and B}}', append_middleware=iter([SeparateCoAuthors()]))
# 'A and B'   wrong

Fix: materialize both arguments to lists at the top of _build_parse_stack and _build_unparse_stack, before anything inspects them. Public annotations stay Iterable; they are now actually honoured.

Tests: 9 regression tests over the public entry points (parse_string, parse_file, write_string, write_file) with generators. Suite: 2739 passed, 12 skipped (was 2730 + 12).

Fixes #531

🤖 Generated with Claude Code

`_build_parse_stack` and `_build_unparse_stack` iterated the passed
`append_middleware`/`prepend_middleware` once to compute the middleware
types and then again to build the stack. With a generator or any other
one-shot iterator (both are valid `Iterable[Middleware]`, as the public
signatures promise) the second pass saw nothing and the middleware was
silently dropped.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@MiWeiss

MiWeiss commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author

lgtm

MiWeiss and others added 2 commits September 3, 2026 23:16
The unparse builder's warning was copied from the parse builder and still
mentioned `append_middleware` / `parse_stack`, which do not exist on the
write path.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@MiWeiss
MiWeiss force-pushed the fix/iterable-middleware-arguments branch from c7d9543 to 95ff0c5 Compare September 3, 2026 21:22
@MiWeiss
MiWeiss merged commit a0eeb2b into main Sep 3, 2026
16 checks passed
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.

Iterator passed as append_middleware/prepend_middleware is silently dropped

1 participant