You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When retrieving a material (api.search(...)) that has previously been created and saved, an error is thrown when trying to parse the json. Upon inspecting the json with @nh916 it appears the cause is an unexpected 'project' item in the retrieved json. Upon further inspection, however, it seems that not all material nodes have this issue. Removing the 'project' item alleviates the issue, but doesn't seem like a long-term solution.
To Reproduce
Code to reproduce is below. Uncommenting del j['project'] alleviates the issue.
import os
import json
import cript
def make_fetch_node(
api, node_name, node_type=cript.Project,
search_mode=cript.SearchModes.EXACT_NAME,
**kwargs
):
res_paginator = api.search(
node_type=node_type,
search_mode=search_mode,
value_to_search=node_name
)
try:
print('* selecting first result on first page *')
to_return = res_paginator.current_page_results[0]
print('* dumping json and loading *')
j = json.loads(json.dumps(to_return))
if node_type == cript.Material:
print('j:\n{}'.format(json.dumps(j, indent=2)))
# del j['project']
j = json.dumps(j)
to_return = cript.load_nodes_from_json(j)
print('* NODE RETRIEVED *')
return to_return
except Exception as ex:
print('ex: {}'.format(ex))
print('* CREATING NODE *')
kwargs['name'] = node_name
if node_type != cript.Project and node_type != cript.Collection:
kwargs['identifier'] = []
return node_type(**kwargs)
api_token = os.environ.get('CRIPT_API_TOKEN')
storage_token = os.environ.get('CRIPT_STORAGE_TOKEN')
api = cript.API(
host='https://api.criptapp.org',
api_token=api_token, storage_token=storage_token
)
api.connect()
print('* making/fetching project *')
project = make_fetch_node(api, node_name='My Toy Project 1234567')
print('* project obtained *')
print('* making/fetching material *')
mat1 = make_fetch_node(
api, node_name='mat2134123134314', node_type=cript.Material
)
print('* material obtained *')
api.save(mat1)
api.save(project)
The ill-formed json, without deleting the 'project' item, is below:
Describe the bug
When retrieving a material (
api.search(...)
) that has previously been created and saved, an error is thrown when trying to parse the json. Upon inspecting the json with @nh916 it appears the cause is an unexpected 'project' item in the retrieved json. Upon further inspection, however, it seems that not all material nodes have this issue. Removing the 'project' item alleviates the issue, but doesn't seem like a long-term solution.To Reproduce
Code to reproduce is below. Uncommenting
del j['project']
alleviates the issue.The ill-formed json, without deleting the 'project' item, is below:
Expected behavior
CRIPT is able to parse json of retrieved material.
Additional context
May be related to trying to retrieve a material name which previously existed but has since been deleted?
The text was updated successfully, but these errors were encountered: