gdcc / pyDataverse

Python module for Dataverse Software (dataverse.org).
http://pydataverse.readthedocs.io/
MIT License
64 stars 45 forks source link

Missing Dataverse upload schema #56

Closed dmelichar closed 3 years ago

dmelichar commented 3 years ago

Expected Behavior

It should be possible to create an Dataverse object from a JSON file, such as this example file.

Current Behavior

The following error is thrown:

FileNotFoundError: [Errno 2] No such file or directory: 'schemas/json/dataverse_upload_schema.json'

Possible Solution

Include Dataverse schema

Steps to Reproduce

napi = NativeApi(base_url=url, api_token=token)
dv = Dataverse()

with open('dataverse.json') as dataverse:
    data = json.load(dataverse)
    dv.set(data)
    try: 
        napi.create_dataverse(identifier=dv.alias, metadata=dv.to_json())

        # Uploading the file directly works, though
        #napi.create_dataverse(identifier=dv.alias, metadata=data)
    except OperationFailedError:
        print("Dataverse already created")

Context (Environment

Branch - develop Commit hash - 3b040ff23b665ec2650bebcf4bd5478de6881af0 Environment - macOS using Pipenv

dmelichar commented 3 years ago

This also seems to be a probem with Dataset objects. I tried to create a new Dataset with the demo file dataset-finch1-json and upload it. Same setup and context as before.

ds1 = Dataset()

with open(dataset1) as df:
    ds1.from_json(df.read()) 
    resp = napi.create_dataset(dataverse=alias, metadata=ds1.to_json())
    print(resp.text)

The error thrown is:

FileNotFoundError: [Errno 2] No such file or directory: 'schemas/json/dataset_upload_default_schema.json'

memetics19 commented 3 years ago

Facing this issue, any workaround?

skasberger commented 3 years ago

@memetics19 yes, if you deactivate validation, the missing schema file is not called. e.g. .to_json(validate=False). But i will try to fix it in the next days.

@dmelichar do you know, how you installed pyDataverse? I have checked, and the file is in the respective place inside the repo, but it is in the repo root directory. So my first guess is, cause the path is relative, that it must be inside the pydataverse folder src/pyDataverse/. So depending on how you install the package, it maybe is not using the repo root as the current working directory or it looks for it inside the src/pyDataverse directory, which only holds the Python files.

skasberger commented 3 years ago

Fix: 6c53b0f