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

Serialization failure when PersonRole::Unknown is involved #266

Open
chenlijun99 opened this issue Jan 11, 2025 · 5 comments
Open

Serialization failure when PersonRole::Unknown is involved #266

chenlijun99 opened this issue Jan 11, 2025 · 5 comments

Comments

@chenlijun99
Copy link

The following code

// path is path to the biblatex file
let contents = fs::read_to_string(path)?;
let bib = hayagriva_io::from_biblatex_str(&contents).unwrap();

Ok(serde_json::to_value(bib).unwrap())

errors out with:

called `Result::unwrap()` on an `Err` value: Error("the enum variant PersonRole::Unknown cannot be serialized", line: 0, column: 0)

I believe this is caused by a wrong use of #serde(skip) in the PersonRole enum.
https://github.com/chenlijun99/hayagriva/blob/af5c146265b797a74edcb0c760e52e41834a037a/src/types/persons.rs#L83-L85

A similar issue was raised in serde: serde-rs/serde#2217 (comment).
The gist seems that the value itself cannot decide to be ignored.

Can be reproduced using the following biblatex entry.

@video{wachowskiMatrix1999,
  type = {Action, Sci-Fi},
  entrysubtype = {film},
  title = {The {{Matrix}}},
  editor = {Wachowski, Lana and Wachowski, Lilly},
  editortype = {director},
  editora = {Wachowski, Lilly and Wachowski, Lana},
  editoratype = {scriptwriter},
  namea = {Reeves, Keanu and Fishburne, Laurence and Moss, Carrie-Anne},
  nameatype = {collaborator},
  date = {1999-03-31},
  publisher = {Warner Bros., Village Roadshow Pictures, Groucho Film Partnership},
  abstract = {When a beautiful stranger leads computer hacker Neo to a forbidding underworld, he discovers the shocking truth--the life he knows is the elaborate deception of an evil cyber-intelligence.},
  keywords = {artificial reality,dystopia,post apocalypse,simulated reality,war with machines},
  annotation = {IMDb ID: tt0133093\\
event-location: United States, Australia}
}
chenlijun99 added a commit to chenlijun99/hayagriva that referenced this issue Jan 11, 2025
@PgBiel
Copy link
Contributor

PgBiel commented Feb 4, 2025

I think this was probably added to ensure persons with unknown roles wouldn't be serialized back into the hayagriva yaml format, but I think this might have been inappropriately handled. In theory, that bibliography cannot be turned into valid hayagriva, as there is a fixed list of allowed roles in the format specification, but maybe we could just flexibilize this restriction, at the cost of breaking some forwards-compatibility. Thoughts? cc @reknih

@reknih
Copy link
Member

reknih commented Feb 4, 2025

I'd rather not allow any value in Hayagriva person roles. I think that the error message that your person was not in the list is valuable, because CSL styles will not select or format arbitrary roles. I also see the need for a generic, catch-all role. Hence, I'd propose changing PersonRole::Unknown(String) to PersonRole::Other and removing its #[serde(skip)]

@PgBiel
Copy link
Contributor

PgBiel commented Feb 4, 2025

Well, that could be an initial improvement. However, I think the problem for this particular case might be different: script-writer is a valid CSL variable and would translate to PersonRole::Writer, but their scriptwriter isn't being interpreted as such - a quick search in interop.rs shows that there is no mention of Writer. And this makes sense as it's not defined in the biblatex standard, so I wonder if we would need to intervene there and consider some non-official translation. In any case, the problem in this issue is different from what we thought.

@reknih
Copy link
Member

reknih commented Feb 4, 2025

I'm open to allow scriptwriter in interop - is there any prior art for this?

@PgBiel
Copy link
Contributor

PgBiel commented Feb 5, 2025

Found this long thread here: retorquere/zotero-better-bibtex#2802
Which links to some other places which also seem to be using scriptwriter.

However, what I can tell for this is that the real "standards" in reference management are very fragmented... and here this is mostly due to how Zotero exports things, if I understood correctly. Maybe we can add a quick hack around this in interop, even if temporarily. But, more generally, it seems that movie/film/video-related attributes are not very well specified by biblatex.

reknih added a commit that referenced this issue Feb 5, 2025
This fixes issue #266.

Other than what the title of the issue suggests, `PersonRole::Unknown` can still not be serialized, deciding [on this](#266 (comment)) is left to a later PR.

Instead, the PR adds some conversions for editor types the biblatex manual does not specify. Support for the `scriptwriter` type is justified by [zotero-better-biblatex's output](https://github.com/retorquere/zotero-better-bibtex/blob/c617185750df065f597a54b447a5b71f690777e4/test/fixtures/export/Exporting%20item%20type%20film%20merges%20scriptwriter%20with%20other%20contributors%20%232802.biblatex#L8). Support for the `producer` type is based on use in both [`biblatex-chicago`](https://markov.htwsaar.de/tex-archive/macros/latex/contrib/biblatex-contrib/biblatex-chicago/doc/biblatex-chicago.pdf) and [`biblatex-apa`](https://ctan.net/macros/latex/contrib/biblatex-contrib/biblatex-apa/biblatex-apa-test-references.bib). `biblatex-apa` uses `writer` instead of `screenwriter`, so that's supported instead.

A peculiarity is that `biblatex-chicago` gives the value `none` the semantic meaning of performers within `video` and `music` entries (see e.g. its manual p. 27). This value is chosen to hack BibLaTeX into not printing any label.
reknih added a commit that referenced this issue Feb 5, 2025
This fixes issue #266.

Other than what the title of the issue suggests, `PersonRole::Unknown` can still not be serialized, deciding [on this](#266 (comment)) is left to a later PR.

Instead, the PR adds some conversions for editor types the biblatex manual does not specify. Support for the `scriptwriter` type is justified by [zotero-better-biblatex's output](https://github.com/retorquere/zotero-better-bibtex/blob/c617185750df065f597a54b447a5b71f690777e4/test/fixtures/export/Exporting%20item%20type%20film%20merges%20scriptwriter%20with%20other%20contributors%20%232802.biblatex#L8). Support for the `producer` type is based on use in both [`biblatex-chicago`](https://markov.htwsaar.de/tex-archive/macros/latex/contrib/biblatex-contrib/biblatex-chicago/doc/biblatex-chicago.pdf) and [`biblatex-apa`](https://ctan.net/macros/latex/contrib/biblatex-contrib/biblatex-apa/biblatex-apa-test-references.bib). `biblatex-apa` uses `writer` instead of `screenwriter`, so that's supported instead.

A peculiarity is that `biblatex-chicago` gives the value `none` the semantic meaning of performers within `video` and `music` entries (see e.g. its manual p. 27). This value is chosen to hack BibLaTeX into not printing any label.
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

No branches or pull requests

3 participants