python-bibtexparser icon indicating copy to clipboard operation
python-bibtexparser copied to clipboard

raise Exception on parsing duplicate key

Open chrisjsewell opened this issue 6 years ago • 2 comments
trafficstars

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.

chrisjsewell avatar Mar 09 '19 23:03 chrisjsewell

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_entry method that would have to be added to it,
  • same as previous but store a set of entries as part of the BibDatabase for efficient check.

omangin avatar Mar 12 '19 07:03 omangin

I have a related question. Suppose that I encounter duplicates: how can I remove one of them for the database?

tdegeus avatar Oct 26 '21 15:10 tdegeus

Fixed in v2

MiWeiss avatar May 26 '23 13:05 MiWeiss