Skip to content

Author sequence in returned API JSON incorrect #7844

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

Open
jnugent opened this issue Apr 8, 2022 · 3 comments
Open

Author sequence in returned API JSON incorrect #7844

jnugent opened this issue Apr 8, 2022 · 3 comments
Assignees
Labels
Bug:1:Minor A bug found in uncommon paths, with low consequences, limited users or has an easy workaround

Comments

@jnugent
Copy link
Member

jnugent commented Apr 8, 2022

Update 2025-04-04

PRs:

stable-3_3_0

Describe the bug
The returned JSON when fetching a publication with an API call of the type:

https://journal.org/index.php/path/api/v1/submissions/xxxxx/publications/xxxxx

Includes the wrong sequence for authors. It sets the seq attribute of all of the authors to the sequence the publication has in the issue. Here is a relevant database record showing the sequence of the publication:

Screenshot at 2022-04-08 11-23-45

And here is the JSON for some of the authors. The author sequence is circled:

authors

I've dumped variables and it seems that this is set this way already, here:

$publication->getData('authors')

Sequence is correctly set in the authors table for the record, and the author string is also correct.

Seen in 3.3.0.8

@jnugent
Copy link
Member Author

jnugent commented Apr 12, 2022

I've done some more digging in this and I suspect the reason for this is that the QueryBuillder for authors selects * here:

$this->columns = ['*', 's.locale AS submission_locale'];

And joins on the publications table. Doesn't this potentially create two seq columns in the result? I think it does, and the JSON is including the publication one, rather than the author one.

This query is also used when fetching authors for other purposes like when building the author string but the sort clause is table specific:

which is why sorting for authors is fine. It's just when you look at the JSON that there's a problem.

@NateWr NateWr added the Bug:1:Minor A bug found in uncommon paths, with low consequences, limited users or has an easy workaround label May 30, 2022
@NateWr NateWr moved this to Backlog in Editorial Workflow May 30, 2022
@JakobRing
Copy link
Contributor

JakobRing commented Apr 2, 2025

I also have a similar but not quite the same problem.

I'm currently building a plugin for OJS 3.3 and when I use $submission = $submissionDao->getById($submissionId); the authors included into the publication included into the submission-object all have the seq from the publication.

Why am I writing this? Because I think (but not sure currently) with this call fetching the data does go another route. So fixing this may be not only a problem of one function but of (some) more?

I think it goes something like this:

SubmissionDao->getById() as it inherits from SchemaDAO

return $row?$this->_fromRow($row):null;

Services::get('publication')->getMany(['submissionIds' => $submission->getId()])

$queryResults = new DAOResultFactory($result, $publicationDao, '_fromRow');

Services::get('author')->getMany(['publicationIds' => $publication->getId()])

$queryResults = new DAOResultFactory($result, $authorDao, '_fromRow');

The $queryResults over here already have the faulty data in them. If I print the first object of the $queryResults->toIterator() its the seq from the publication and not from the author.

EDIT: I dug some more and found that it also goes into the PKPAuthorQueryBuilder::getQuery().
And as @jnugent suggested, I also think that

$this->columns = ['*', 's.locale AS submission_locale'];
is the problem.

For this case changing the * to a.* does fix the problem for me and the correct seq are included into the author-objects (and nothing else is changed inside the whole submission object). BUT: I don't know if this change does affect some other methods so that these don't work correctly anymore but I don't think so. I hope that this comment was helpful to fix the problem.

ewhanson added a commit to ewhanson/pkp-lib that referenced this issue Apr 4, 2025
@ewhanson
Copy link
Contributor

ewhanson commented Apr 4, 2025

Thanks for sharing the additional info and your fix, @JakobRing. Will get this updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug:1:Minor A bug found in uncommon paths, with low consequences, limited users or has an easy workaround
Projects
Status: Backlog
Development

No branches or pull requests

6 participants