sciunto-org / python-bibtexparser

Bibtex parser for Python 3
https://bibtexparser.readthedocs.io
MIT License
474 stars 132 forks source link

Parsing fails when bibtex contains duplicates #378

Closed rcannood closed 1 year ago

rcannood commented 1 year ago

Based on the v2 docs, it seems bibtexparser should be able to process bibtex files with duplicates. However, if a bibtex file contains duplicates, an error is produced:

import bibtexparser
str = """@article{duplicate,
  author = {Duplicate, A.},
  title = {Duplicate article},
  year = {2022},
}
@article{duplicate,
  author = {Duplicate, A.},
  title = {Duplicate article},
  year = {2022},
}"""

bibtexparser.parse_string(str)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/.local/lib/python3.10/site-packages/bibtexparser/entrypoint.py", line 93, in parse_string
    library = middleware.transform(library=library)
  File "~/.local/lib/python3.10/site-packages/bibtexparser/middlewares/interpolate.py", line 60, in transform
    for field in entry.fields:
AttributeError: 'DuplicateEntryKeyBlock' object has no attribute 'fields'
MiWeiss commented 1 year ago

Successfully reproduced. Thanks!

rcannood commented 1 year ago

Thanks for the quick response :bow: !

MiWeiss commented 1 year ago

In a couple of minutes, I'll merge #379 which should fix the issue. Please re-install bibtexparser and try again.

Note: You will find the duplicate in the library.failed_blocks collection.