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

serializers: access values only if set #1731

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

Conversation

rekt-hard
Copy link
Contributor

❤️ Thank you for your contribution!

Description

Perform resource type vocabulary lookup only if resource type is set.
Parse dates only if they are set

Checklist

Ticks in all boxes and 🟢 on all GitHub actions status checks are required to merge:

Third-party code

If you've added third-party code (copy/pasted or new dependencies), please reach out to an architect.

Reminder

By using GitHub, you have already agreed to the GitHub’s Terms of Service including that:

  1. You license your contribution under the same terms as the current repository’s license.
  2. You agree that you have the right to license your contribution under the current repository’s license.

@utnapischtim
Copy link
Contributor

is this a bugfix or a feature?

@rekt-hard
Copy link
Contributor Author

rekt-hard commented Apr 18, 2024

Bugfix. It is only about making sure the values exist before performing a lookup or trying to parse it.

For example, performing the following steps will lead to an error:

  • Create a new draft
  • Remove the publication date
  • Save the draft
  • Navigate to https://127.0.0.1:5000/records/<draft-id>/export/json-ld?preview=1

I will just create an issue out of this

@rekt-hard rekt-hard linked an issue Apr 18, 2024 that may be closed by this pull request
@utnapischtim
Copy link
Contributor

would it not be better to use a try except block?

try:
    resource_type_id = obj["metadata"]["resource_type"]["id"]
except KeyError:
    return missing

or is the "resource_type.id" always there?
the same could be applied to the other changes as well

@rekt-hard
Copy link
Contributor Author

Right - good catch. Not sure about it being there.
In other places something like this is used: resource_type_id = py_.get(obj, "metadata.resource_type.id") (which will return None if any intermediate attribute is not available)

Would go for that.

@rekt-hard rekt-hard force-pushed the serializers-get-types branch 2 times, most recently from f390170 to 4a838c5 Compare April 18, 2024 16:10
@rekt-hard rekt-hard changed the title serializers: get type vocabulary only if set serializers: access values only if set Apr 19, 2024
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.

Error when serializing draft
2 participants