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

[#3688] Use Documents URLs as fileupload variables values #4032

Merged
merged 13 commits into from
Mar 22, 2024

Conversation

Viicos
Copy link
Contributor

@Viicos Viicos commented Mar 20, 2024

Part of #3688, #4019

@Viicos Viicos force-pushed the feature/3688-attachments branch 3 times, most recently from 162d93f to 7d4112c Compare March 21, 2024 14:45
@Viicos Viicos marked this pull request as ready for review March 21, 2024 14:59
@Viicos Viicos requested a review from SilviaAmAm March 21, 2024 14:59
src/openforms/registrations/contrib/objects_api/models.py Outdated Show resolved Hide resolved
Comment on lines 223 to 243
try:
ObjectsAPISubmissionAttachment.objects.get(
submission_file_attachment=attachment
)
except ObjectsAPISubmissionAttachment.DoesNotExist:
ObjectsAPISubmissionAttachment.objects.create(
submission_file_attachment=attachment,
documents_url=register_submission_attachment(
submission, attachment, options, documents_client
),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand correctly, this prevents that if the Objects API registration fails, the attachments are sent again to the Documents API during the retry flow?

@Viicos Viicos force-pushed the feature/3688-attachments branch 3 times, most recently from a6f6552 to 3799efc Compare March 22, 2024 11:02
Copy link

codecov bot commented Mar 22, 2024

Codecov Report

Attention: Patch coverage is 97.77778% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 96.07%. Comparing base (1d922e5) to head (92b2832).

Files Patch % Lines
...ons/contrib/objects_api/submission_registration.py 96.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4032      +/-   ##
==========================================
+ Coverage   96.06%   96.07%   +0.01%     
==========================================
  Files         728      728              
  Lines       22854    22867      +13     
  Branches     2650     2654       +4     
==========================================
+ Hits        21954    21970      +16     
+ Misses        637      636       -1     
+ Partials      263      261       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +234 to +243
for attachment in submission.attachments:
if attachment not in existing:
objs.append(
ObjectsAPISubmissionAttachment(
submission_file_attachment=attachment,
document_url=register_submission_attachment(
submission, attachment, options, documents_client
),
)
)
Copy link
Member

Choose a reason for hiding this comment

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

(please create a follow up issue for this)

This can still cause (repeated) failures - if you have two documents and the first succeeds, while the second does not, the for-loop will crash out and it will never be persisted that the first document creation actually succeeded.

you'll probably want to try: around this to make sure that you can create the model instances for whatever's in objs in the finally block:

try:
    for attachmenet in ...:
        # do the stuff
except:
    raise
finally:
    ObjectsAPISubmissionAttachment.objects.bulk_create(objs)

Copy link
Member

Choose a reason for hiding this comment

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

Created #4041

Comment on lines +380 to +390
for key in dynamic_values.keys():
if key in urls_map:
variable = state.get_variable(key)
is_multiple = variable.form_variable.form_definition.configuration_wrapper.component_map[
key
].get(
"multiple", False
)
dynamic_values[key] = (
urls_map[key][0] if not is_multiple else urls_map[key]
)
Copy link
Member

Choose a reason for hiding this comment

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

I did some reasoning about the form_variable FK potentially being None and how this works if registration is run after a file-upload component is removed from the form, and I concluded it's not an issue, because:

  • state is used, which ensures that we only consider currently available form variables (through the collect_variables method)
  • dynamic_values is used, which relies on the above state considering only currently available form variables

So there may be extra SubmissionFileAttachment records for the submission, and those will exist in our DB but not sent along to the objects API. And this behaviour is as (currently) intended.

Accessing dotted-keys like foo.bar in the underlying data
structure used by FormioData does not work, the point of
FormioData is to abstract this access.
@Viicos Viicos merged commit 75c3268 into master Mar 22, 2024
25 of 27 checks passed
@Viicos Viicos deleted the feature/3688-attachments branch March 22, 2024 13:11
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.

3 participants