Replies: 2 comments 1 reply
-
Changing the name of the material works sometimes, but other times it throws the error below, which I don't know what to make of? (the project/collection/material names are different than above, but created using the same process) cript.api.exceptions.CRIPTAPISaveError: API responded to POST with 'http:400 'node' is a required property at path: properties/collection/items' data: {"node": ["Project"], "uid": "_:c855b0c5-ce7a-4f9d-8b05-0a7ec8e17f05", "uuid": "c855b0c5-ce7a-4f9d-8b05-0a7ec8e17f05", "name": "Project Test Shared Materials 12345678", "collection": [{"uuid": "435af0dd-0e6b-4aa6-afca-c532d340aa5b"}], "material": [{"node": ["Material"], "uid": "_:04e2d61c-bdd2-4397-aecb-ac489b6088d6", "uuid": "04e2d61c-bdd2-4397-aecb-ac489b6088d6", "name": "Benzoic Acid 1234", "names": ["Benzoic Acid 1234"]}]} |
Beta Was this translation helpful? Give feedback.
-
Hi @c-heat16, thank you for the detailed code and error log, that really helps. I tried to reproduce your code with my own script and I was able to successfully reproduce it. I think this is an API issue. I've created a ticket for the API and have notified our software engineer. The only temporary work around that I can think of at the moment is to use unique names for the project to avoid this issue, however, that could get messy very quickly. I think the permanent solution would be from the API to allow uploads with the same name after deletion. @brili might be able to provide a better answer or add more context to this.
import datetime
import os
import cript
with cript.API(host="https://lb-stage.mycriptapp.org/", api_token=os.getenv("CRIPT_TOKEN"),
storage_token=os.getenv("CRIPT_STORAGE_TOKEN")) as api:
# current time to keep the node names unique
current_time = str(datetime.datetime.now())
# create needed nodes
my_project = cript.Project(name=f"my project name {current_time}")
my_collection = cript.Collection(name=f"my collection name {current_time}")
my_experiment = cript.Experiment(name=f"my experiment name {current_time}")
my_reference = cript.Reference(type="journal_article", title=f"my title {current_time}")
my_citation = cript.Citation(type="reference", reference=my_reference)
my_material = cript.Material(
name=f"my material name {current_time}", identifier=[{"names": [f"my material name {current_time}"]}]
)
# assemble the nodes
my_project.collection = [my_collection]
my_project.collection[0].experiment = [my_experiment]
my_project.collection[0].experiment[0].citation = [my_citation]
my_project.material = [my_material]
api.save(project=my_project)
api.delete(node=my_project)
api.save(project=my_project) raise CRIPTDuplicateNameError(response, json_data, exc) from exc
cript.api.exceptions.CRIPTDuplicateNameError: The name 'my project name 2023-11-06 15:32:40.698160' for your Project node is already present in CRIPT. Either choose a new name! |
Beta Was this translation helpful? Give feedback.
-
If we create a project in a python script, and at the end of the script call
api.delete(project)
should we be able to run the script again afterwards?Seems like the answer should be yes, but I am encountering different behavior. The script below will create a project, collection, and material and then delete the project at the end with a call to
api.delete(project)
and gives a message that the project has been deleted. However, trying to run the script again gives a message that a project with the same name already exists.Message for successful delete after first run:
INFO: Deleted 'Project' with UUID of 'd100a7d0-60c5-4306-9a9b-aec98b0a5c0b' from CRIPT API.
Trace on subsequent run:
Code:
Beta Was this translation helpful? Give feedback.
All reactions