Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

duplicates in display_order create duplicate entries #252

Open
jakob-kellner opened this issue Feb 25, 2020 · 2 comments
Open

duplicates in display_order create duplicate entries #252

jakob-kellner opened this issue Feb 25, 2020 · 2 comments

Comments

@jakob-kellner
Copy link

bibtexparser 1.1.0.

Not a big problem, but confused me for a while:

If the list assigned to writer.display_order contains a key more than once,
then the according line in the bibentry will also be created more than once.
E.g.:

import bibtexparser
bib_dict = {'ID': 'a', 'ENTRYTYPE': 'misc', 'title': 'b', 'year': '1'}
my_db = bibtexparser.bibdatabase.BibDatabase()                               
my_db.entries = [bib_dict]
writer = bibtexparser.bwriter.BibTexWriter()                                           
writer.display_order = ['title', 'dummy', 'title'] 
print( bibtexparser.dumps(my_db, writer)) 

results in

@misc{a,
 title = {b},
 title = {b},
 year = {1}
}

I do not even claim that this is a bug, but maybe a short comment in the documentation could be added.

@sciunto
Copy link
Member

sciunto commented Feb 27, 2020

Thanks for reporting. I would be inclined to convert the input into set in the function as it does not make sense to duplicate entries. Any other opinion @omangin ?

@MiWeiss
Copy link
Collaborator

MiWeiss commented Jul 9, 2022

@omangin I would not use sets directly, as those are by definition unordered (thus we would rely, AFAIK, on some undocumented implementation of set to preserve order).

This almost certainly shows a mistake by the user, and instead of silently attempting some fix, I suggest raising an exception if the display_order contains duplicates. Doing so requires a setter, thus display_order would have to be transferred into a property.

Is anyone volunteering to implement this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants