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

Editing a Project can delete uploads. #209

Closed
bmatern opened this issue Oct 26, 2021 · 7 comments · Fixed by #210
Closed

Editing a Project can delete uploads. #209

bmatern opened this issue Oct 26, 2021 · 7 comments · Fixed by #210
Labels
bug Something isn't working

Comments

@bmatern
Copy link
Contributor

bmatern commented Oct 26, 2021

This one's pretty nasty, when we edit a project, then some uploads assigned to the project can disappear. (stilll exist in S3 but the link seems to be gone)

Related: #202

@bmatern bmatern added the bug Something isn't working label Oct 27, 2021
@bmatern
Copy link
Contributor Author

bmatern commented Nov 2, 2021

Seems like Hibernate is doing some thing with the data, based on assumptions.

When we change project details, ProjectResource.java is using the updateProject REST method.

This method eventually calls:
Project result = projectRepository.save(project);

When the save() method executes, Hibernate is doing the following 4 things (Haven't found this in the code, although I think it's buried in Spring somewhere, this is from the logs):

  1. Get info about all uploads connected to project
    Hibernate: select ... from upload left outer join ihiw_user left outer join ihiw_lab left outer join jhi_user left outer join upload
    (indeed it's getting upload data twice, because of our parent/child relationship)

  2. Update the Project
    Hibernate: update project set activated=?, component=?, created_at=?, created_by_id=?, description=?, modified_at=?, modified_by_id=?, name=? where id=?

  3. Update Uploads
    Hibernate: update upload set created_at=?, created_by_id=?, enabled=?, file_name=?, modified_at=?, parent_upload_id=?, project_id=?, type=? where id=?

  4. Delete uploads and Validations?!?
    Hibernate: delete from validation where id=?
    Hibernate: delete from upload where id=?

So Hibernate is doing quite presumptious things. Presumably because of foreign key relationships.

@bmatern
Copy link
Contributor Author

bmatern commented Nov 2, 2021

Here are some of the foreign keys right now:

fk_upload_upload
on update restrict
on delete restrict

fk_upload_project
on update restrict
on delete restrict

fk_upload_created_by_id
on update restrict
on delete set null

fk_ihiw_user_lab_id
on update restrict
on delete restrict

fk_ihiw_user_user_id
on update restrict
on delete cascade

fk_validation_upload_id
on update restrict
on delete cascade

fk_project_created_by_id
on update restrict
on delete set null

fk_project_modified_by_id
on update restrict
on delete restrict

To me none of this suggests uploads should delete when project is updated.

@bmatern
Copy link
Contributor Author

bmatern commented Nov 2, 2021

I think the problem is not with how the foreign keys are defined. The problem may be Project.java and ProjectDTO.java are incomplete.

Evidence: When I debug the updateProject method in ProjectResource.java, it looks like there are ZERO uploads attached to the project, I would expect to see the uploads attached.
image

So when we save() the project it, it's saving the project with no uploads attached.

It does look like ProjectDTO.java is incomplete (No reference to uploads here!) , and there may be problems with the OneToMany mapping of uploads in Project.java.
image

image

@bmatern
Copy link
Contributor Author

bmatern commented Nov 2, 2021

Project.java and ProjectDTO.java have some changes that indeed allow the uploads to be carried along. (Branch feature/209)

However the edit update form does not load/save these uploads.

Some changes are still needed on project-update.component.ts

@bmatern
Copy link
Contributor Author

bmatern commented Nov 3, 2021

As suggested by Matthias, the updateProject Rest method directly pulls the uploads from the database
project.setUploads(projectFromDB.get().getUploads());

Seems to resolve the issue.

@bmatern bmatern linked a pull request Nov 3, 2021 that will close this issue
@bmatern
Copy link
Contributor Author

bmatern commented Nov 8, 2021

"New and Exciting" issue with this deploy to staging, Possibly caused by these fixes, or maybe #196 or #211

deleteUpload is failing in some cases. The S3 file is indeed successfully removed, but Liquibase Hibernate is not deleting the database Upload row.

To recreate the issue:

  1. Create a new upload
  2. Edit the Project this upload is assigned to.
  3. On Uploads list, delete the upload we just made.
  4. Failure: The S3 file is indeed deleted, but Liquibase Hibernate is not deleting the database Upload row.

I do not see the bug when I do this:

  1. Create a new upload
  2. On Uploads list, immediately delete the upload we just made.
  3. Success: The S3 file AND the database row are deleted.

I can see "Hibernate: delete from upload where id=?" In the log in this case. This does not appear in the error case.

@bmatern
Copy link
Contributor Author

bmatern commented Nov 8, 2021

I can also recreate by

  1. Create a new upload
  2. Stop and Restart the Webserver
  3. On Uploads list, delete the upload we just made.
    Failure: The S3 file is indeed deleted, but Liquibase Hibernate is not deleting the database Upload row.

So i think uploadRepository is not finding the upload properly when I call deleteById(); and it is not directly caused by editing the project.

@bmatern bmatern closed this as completed May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant