sci-ndp / scidx-py

sciDX Science Data Exchange
Apache License 2.0
0 stars 1 forks source link

isuue regarding registering a url #38

Open saleemalharir1 opened 2 months ago

saleemalharir1 commented 2 months ago
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[144], line 5
      2 parent_dict = {}
      3 file_path = '/home/finley/test_dict.json'
----> 5 create_parent_dict(link, parent_dict, file_path)

Cell In[143], line 9, in create_parent_dict(link, parent_dict, file_path)
      5 links = get_csv_links(link)
      7 for link in links:
----> 9     create_erthscp_dict(link, parent_dict, i)
     12     i += 1
     14 save_dict_to_json(parent_dict, file_path)

Cell In[140], line 25, in create_erthscp_dict(url, parent_dict, i)
     21 name = 'erthscp_dict_' + str(i)
     23 parent_dict[name] = data
---> 25 client.register_url(**data)

File ~/.local/lib/python3.10/site-packages/scidx/client/register_url.py:164, in register_url(self, resource_name, resource_title, owner_org, resource_url, file_type, processing, notes, extras, mapping)
    152 headers = self._get_headers()
    154 # Build the payload
    155 payload = {
    156     "resource_name": resource_name,
    157     "resource_title": resource_title,
    158     "owner_org": owner_org,
    159     "resource_url": resource_url,
    160     "file_type": file_type,
    161     "notes": notes,
    162     "extras": extras or {},
    163     "mapping": mapping or {},
--> 164     "processing": processing.to_dict(),
    165 }
    167 response = requests.post(url, json=payload, headers=headers)
    168 if response.status_code == 201:

AttributeError: 'dict' object has no attribute 'to_dict'
philip-davis commented 2 months ago

I am seeing a regression to his now that processing is an optional parameter.

I suggest something like this:

# Build the payload
   payload = {
       "resource_name": resource_name,
       "resource_title": resource_title,
       "owner_org": owner_org,
       "resource_url": resource_url,
       "file_type": file_type,
       "notes": notes,
       "extras": extras or {},
       "mapping": mapping or {},
   }

   if processing:
       payload['processing'] = processing.to_dict()

The problem with any resolution to this in the client is that processing is being validated against the file_type-specific model in the API. I'm opening a ticket for this in the scidx-api repo, since that's where the handling comes out.

Andreufb commented 2 months ago

Hi Philip! This has been resolved in the branch, the new version looks like this: payload = { "resource_name": resource_name, "resource_title": resource_title, "owner_org": owner_org, "resource_url": resource_url, "notes": notes, "extras": extras or {}, "mapping": mapping or {}, }

if file_type:
    payload["file_type"] = file_type
if processing:
    payload["processing"] = processing.to_dict()

By the end of today I will send the merge request of the actual branch I am working on.