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

Fix updating ID for resource #3239

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open

Conversation

ThibaudDauce
Copy link
Contributor

No description provided.

@bolinocroustibat bolinocroustibat self-requested a review January 2, 2025 17:29
Copy link
Contributor

@bolinocroustibat bolinocroustibat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, that was quickly done!
Would that make sense, in the future, to create the ID on udata server side?

@ThibaudDauce
Copy link
Contributor Author

LGTM, that was quickly done! Would that make sense, in the future, to create the ID on udata server side?

The front-end is using the client side ID generation to send in parallel all the chunks so not sure it's possible without changing the API (for exemple having a client side UUID then a real UUID saved in the database at the end of the upload process)… https://github.com/datagouv/front-end/blob/700fa2e57f9ae347c7b59e8eb1e5dbbff659a475/utils/datasets.ts#L175-L214

Copy link
Contributor

@magopian magopian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks for the investigation and resolution, good job!

Copy link
Contributor

@maudetes maudetes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the investigation and proposed solution!

I don't think the resource id field is currently set by the frontend.
The uuid header in the multipart isn't currently used to create the Resource object, it is only used to identify the chunks the file belong to.
Comparing the uuid with the resource id shows they differ in this chunk upload test case.

I think we should make sure the resource id field is entirely readonly instead.

Copy link
Contributor

@maudetes maudetes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll need to deal with existing duplicated resources ID before merging & deploying?

Copy link
Contributor

@maudetes maudetes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have minor comments but then we can merge I think!

form = api.validate(ResourceForm)
resource = Resource()
form = api.validate(ResourceFormWithoutId)
resource = Resource(id=str(uuid4()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you setting the id explicitly here?

Comment on lines +72 to +76
try:
dataset.add_resource(resource_b)
assert False
except RuntimeError:
print("Ok!")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
try:
dataset.add_resource(resource_b)
assert False
except RuntimeError:
print("Ok!")
with pytest.raises(RuntimeError):
dataset.add_resource(resource_b)

@@ -897,6 +900,9 @@ def get(cls, id_or_slug):
def add_resource(self, resource):
"""Perform an atomic prepend for a new resource"""
resource.validate()
if resource.id in [r.id for r in self.resources]:
raise RuntimeError("Cannot add resource with already existing ID")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be a RuntimeError by the way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the policy on errors. Do we create a new error type? Do we use something generic?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say we could use a MongoEngineValidationError as you did above?

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

Successfully merging this pull request may close these issues.

4 participants