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

Validation for note transitions #4528

Open
angoca opened this issue Feb 19, 2024 · 7 comments
Open

Validation for note transitions #4528

angoca opened this issue Feb 19, 2024 · 7 comments

Comments

@angoca
Copy link

angoca commented Feb 19, 2024

URL

https://api.openstreetmap.org/api/0.6/notes/52751

How to reproduce the issue?

I am analyzing the notes dump from Planet and found this invalid transition: reopen twice.

image

This is impacting the validations I am doing on my code.

I would like to know if this is normal (no validation). Or what is the issue behind this?

Screenshot(s) or anything else?

No response

@AntonKhorev
Copy link
Contributor

You are not guaranteed to see all comments.

  1. user A reopens the note
  2. user B closes the note
  3. user A reopens the note again
  4. user B deletes their account - now you won't see (2), you'll see two reopens

@angoca
Copy link
Author

angoca commented Feb 19, 2024

Hi Anton, Thanks for your example, but this is not the case. The date/time is the same for the 2 "reopen" actions, with the same user (vramirez) who still has an active account.

@AntonKhorev
Copy link
Contributor

Ok, the two reopens at 2013-10-05 15:13:48 UTC probably didn't happen as I described, but that's still a possible scenario.

Maybe it's possible to reopen a note twice if the requests are done quick enough. The api code didn't change much since it was added in d74d4f8.

@angoca
Copy link
Author

angoca commented Feb 19, 2024

Therefore, you confirm that this is a bug that the API has, which does not check the current status when a new status arrives, and it is the same.

I have found the other case, close a closed note: 19523

image

@angoca
Copy link
Author

angoca commented Feb 19, 2024

I have found other interesting cases:

I put the complete list here: https://wiki.openstreetmap.org/wiki/User:Angoca/invalidTransitions

@mmd-osm
Copy link
Contributor

mmd-osm commented Feb 19, 2024

Maybe it's possible to reopen a note twice if the requests are done quick enough

At least checking the current status of a note (Note.find_by_id(id) ... raise OSM::APINoteAlreadyOpenError.new(@note) unless @note.closed?) is done without exclusive or optimistic locking (based on version numbers).

If multiple API requests for the same note are processed at the same time, such duplicates can occur.

@tomhughes
Copy link
Member

There is a check for duplicate closes (https://github.com/openstreetmap/openstreetmap-website/blob/master/app/controllers/api/notes_controller.rb#L181) and has been since ae27f7a in February 2013 but as it is at the application layer two closes very close together might still make it to the database because both might pass the check before either one has made the change as the check is not inside a transaction and there is no constraint in the database that would block it.

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

4 participants