python-bibtexparser
python-bibtexparser copied to clipboard
raise Exception on parsing duplicate key
I can't see an option to make this happen? At present an entry is silently overwritten by a preceding entry with the same key.
Technically it is not completely ignored: entries with duplicate citekeys are actually parsed and stored in the entries attribute of the BibDatabase object (which is a list). So you can still retrieve it and decide then to check for duplicates and raise an exception. They however disappear if you access the entries_dict of the BibDatabase object instead.
However, I can see cases where such an exception could be useful at parse time and a PR in that direction would be welcome! For now I will classify it as a features request but thanks @chrisjsewell for reporting it!
This could be implemented in several ways:
- just add a check before https://github.com/sciunto-org/python-bibtexparser/blob/master/bibtexparser/bparser.py#L301 and raise an exception when necessary,
- make this an option of the BibDatabase object and check within a
add_entrymethod that would have to be added to it, - same as previous but store a set of entries as part of the
BibDatabasefor efficient check.
I have a related question. Suppose that I encounter duplicates: how can I remove one of them for the database?
Fixed in v2