Skip to content

Make InvalidNameError copyable and picklable - #599

Open
eeshsaxena wants to merge 1 commit into
sciunto-org:mainfrom
eeshsaxena:invalidnameerror-copyable
Open

Make InvalidNameError copyable and picklable#599
eeshsaxena wants to merge 1 commit into
sciunto-org:mainfrom
eeshsaxena:invalidnameerror-copyable

Conversation

@eeshsaxena

Copy link
Copy Markdown

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
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!

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.

1 participant