Skip to content

🐛 Make InvalidNameError copyable and picklable - #599

Merged
MiWeiss merged 2 commits into
sciunto-org:mainfrom
eeshsaxena:invalidnameerror-copyable
Sep 2, 2026
Merged

MiWeiss merged 2 commits into
sciunto-org:mainfrom
eeshsaxena:invalidnameerror-copyable

Conversation

@eeshsaxena

Copy link
Copy Markdown
Contributor

InvalidNameError can't be copied or pickled, which crashes normal parsing:

import copy
from bibtexparser.middlewares.names import InvalidNameError
copy.deepcopy(InvalidNameError(name="Doe, John", reason="Too many commas"))
# TypeError: InvalidNameError.__init__() missing 1 required positional argument

Its __init__ takes name and reason but the base ValueError only keeps the formatted message in args, so deepcopy/pickle rebuild it with a single argument. This surfaces through the public API: a failed name is stored in a MiddlewareErrorBlock, and a later middleware like SortBlocksByTypeAndKeyMiddleware deepcopies the whole library, so any bad author name plus that middleware raises TypeError out of parse_string. I store name/reason and add __reduce__ so it round-trips. Added a test.

InvalidNameError takes name and reason, but its base only stores the
formatted message in args, so copy.deepcopy and pickle rebuild it with a
single argument and raise TypeError. That surfaces through normal parsing:
a failed name is kept in a MiddlewareErrorBlock, and a later middleware
like SortBlocksByTypeAndKeyMiddleware deepcopies the library.

Store name and reason and add __reduce__ so the exception round-trips.
@eeshsaxena

Copy link
Copy Markdown
Contributor Author

Hi! Gentle nudge on this one whenever you have some bandwidth. It's a small, self-contained fix (Make InvalidNameError copyable and picklable), and it's currently mergeable with no conflicts. No urgency at all, and I'm happy to make any changes you'd like. Thanks for maintaining python-bibtexparser!

Remove unnecessary comments from the custom exception class.
@MiWeiss MiWeiss changed the title Make InvalidNameError copyable and picklable 🐛 Make InvalidNameError copyable and picklable Sep 2, 2026
@MiWeiss
MiWeiss enabled auto-merge (squash) September 2, 2026 19:25
@MiWeiss

MiWeiss commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Thanks a lot for your contribution!

@MiWeiss
MiWeiss disabled auto-merge September 2, 2026 19:30
@MiWeiss
MiWeiss merged commit 705cac0 into sciunto-org:main Sep 2, 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.

2 participants