Skip to content

🐛 Fix misleading 'Unknown block type' warning for failed blocks and add missing DuplicateFieldKeyBlock.entry (#520)#523

Merged
MiWeiss merged 3 commits into
mainfrom
520-duplicate-field-key-block
Jun 11, 2026
Merged

🐛 Fix misleading 'Unknown block type' warning for failed blocks and add missing DuplicateFieldKeyBlock.entry (#520)#523
MiWeiss merged 3 commits into
mainfrom
520-duplicate-field-key-block

Conversation

@MiWeiss

@MiWeiss MiWeiss commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Fixes #520

What was wrong

As reported in #520, parsing a bib file containing an entry with duplicate field keys produced the confusing warning

Unknown block type <class 'bibtexparser.model.DuplicateFieldKeyBlock'>

and offered no documented way to inspect the problem. Three distinct issues were behind this:

  1. Misleading warning: BlockMiddleware.transform_block had no branch for ParsingFailedBlock and its subtypes, so any block middleware (including RemoveEnclosingMiddleware from the default parse stack) fell through to the "Unknown block type" warning for every failed block — even though these are well-known model types that are intentionally passed through.
  2. Wrong error message: the DuplicateFieldKeyBlock error message told users the entry is "available as failed_block.entry", but no such attribute exists — the entry is available as failed_block.ignore_error_block. This is the "another problem shadowing correct behavior" suspected in the issue discussion.
  3. Missing documentation: the failed-block types were not part of the API docs, and the quickstart's error-checking section referred to a "corresponding section of the docs" that didn't exist.

Changes

  • BlockMiddleware now handles ParsingFailedBlock explicitly via a new overridable transform_failed_block hook, which by default keeps failed blocks unchanged (and silent). Custom middlewares can override it if they want to process failed blocks.
  • Fixed the DuplicateFieldKeyBlock error message to reference the existing ignore_error_block attribute (consistent with the other ParsingFailedBlock subtypes), instead of the non-existent .entry.
  • Documented ParsingFailedBlock, MiddlewareErrorBlock, DuplicateBlockKeyBlock and DuplicateFieldKeyBlock in the API docs, added Library.failed_blocks to the Library docs, and expanded the quickstart error-checking section with the available attributes (error, start_line, raw, ignore_error_block, ...).
  • Bumped two pre-commit hook pins (language-formatters-pre-commit-hooks, docstr_coverage) whose pinned versions crash in current CI environments with ModuleNotFoundError: No module named 'pkg_resources'; their latest releases dropped the pkg_resources dependency.
  • Tests: failed blocks pass through BlockMiddleware unchanged without any warning; DuplicateFieldKeyBlock.duplicate_keys and the corrected error message are asserted in the splitter tests.

Before / after

import bibtexparser
lib = bibtexparser.parse_string("""
@article{Smith2020,
  title = {A title},
  title = {A duplicate title},
}
""")

Before: logs Unknown block type <class 'bibtexparser.model.DuplicateFieldKeyBlock'>; the error message points to failed_block.entry, which raises AttributeError.

After: no warning; the error message points to failed_block.ignore_error_block, which returns the entry including both title fields, and lib.failed_blocks[0].duplicate_keys == {"title"}.

Full test suite passes (2475 passed, 12 skipped), pre-commit hooks pass.

🤖 Generated with Claude Code

MiWeiss and others added 3 commits June 11, 2026 23:10
BlockMiddleware.transform_block did not recognize ParsingFailedBlock
and its subtypes (e.g. DuplicateFieldKeyBlock), causing a confusing
'Unknown block type' warning with the default parse stack whenever an
entry contained duplicate field keys. Failed blocks are now passed
through silently via an overridable `transform_failed_block` hook.

Also adds the `entry` property on DuplicateFieldKeyBlock, which the
error message promised but which did not exist, and documents the
failed-block types in the quickstart and API docs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
language-formatters-pre-commit-hooks v2.12.0 and docstr_coverage v2.3.0
crash on import in current CI environments (ModuleNotFoundError:
pkg_resources). Both dropped the pkg_resources dependency in their
latest releases.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Instead of adding the `entry` alias promised by the (wrong) error
message, fix the message to reference `ignore_error_block`, keeping
the failed-block API consistent across all ParsingFailedBlock
subtypes.

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

@MiWeiss MiWeiss left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

reviewed

@MiWeiss MiWeiss merged commit b0911e4 into main Jun 11, 2026
19 checks passed
@MiWeiss MiWeiss deleted the 520-duplicate-field-key-block branch June 11, 2026 21:27
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.

What is bibtexparser.model.DuplicateFieldKeyBlock ?

1 participant