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

Fix creating EDGE dataset without product attribute specified #16

Merged
merged 1 commit into from
Feb 1, 2024

Conversation

MauDagos
Copy link
Contributor

@MauDagos MauDagos commented Feb 1, 2024

Requesting a creation of a dataset to the EDGE RPApi would fail if the Dataset had no product specified:

import os
 
from ravenpackapi import Dataset, RPApi
 
if __name__ == "__main__":
    api = RPApi(api_key=os.getenv("RP_API_KEY"), product="edge")
 
    entity_relevance = "relevance"  # For RPA
    entity_relevance = "entity_relevance"  # For EDGE
 
    ds = api.create_dataset(
        Dataset(
            name="New Dataset",
            filters={entity_relevance: {"$gte": 90}},
        )
    )
 
    print("Dataset created", ds)

Would return:

Error calling the API, we tried: curl -X POST -H 'API_KEY:CMO2m4xx1bzcA5dU89CPuV' -d '{"product": "RPA", "product_version": "1.0", "name": "New Dataset", "filters": {"entity_relevance": {"$gte": 90}}}' 'https://api-edge.ravenpack.com/1.0/datasets'
Traceback (most recent call last):
  File "/home/mdagostino/workspace/python-api/pcp-13076.py", line 11, in <module>
    ds = api.create_dataset(
  File "/home/mdagostino/workspace/python-api/ravenpackapi/core.py", line 160, in create_dataset
    new_dataset.save()
  File "/home/mdagostino/workspace/python-api/ravenpackapi/exceptions.py", line 64, in decorated_func
    return func(instance, *args, **kwargs)
  File "/home/mdagostino/workspace/python-api/ravenpackapi/models/dataset.py", line 207, in save
    response = self.api.request(endpoint=endpoint, json=data, method=method)
  File "/home/mdagostino/workspace/python-api/ravenpackapi/core.py", line 123, in request
    raise get_exception(response)
ravenpackapi.exceptions.APIException: Got an error 400: body was '{"endpoint":"datasets","errors":[{"type":"ValidationError","reason":"Field 'product' must be 'edge'","parameter_name":"product","value":"RPA"}]}'

Now this workflow works as expected.

One downside is that it's now possible for a Dataset object to have a None product.

@MauDagos MauDagos assigned joserc87 and MauDagos and unassigned joserc87 and MauDagos Feb 1, 2024
@MauDagos MauDagos requested a review from joserc87 February 1, 2024 10:41
@MauDagos MauDagos changed the title Fix creating EDGE dataset without product attribute unspecified Fix creating EDGE dataset without product attribute specified Feb 1, 2024
@MauDagos MauDagos force-pushed the fix-creating-edge-dataset branch from a31d201 to 2e6fa30 Compare February 1, 2024 10:47
Copy link
Contributor

@joserc87 joserc87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@joserc87 joserc87 merged commit 8c6e0f0 into master Feb 1, 2024
3 checks passed
@joserc87 joserc87 deleted the fix-creating-edge-dataset branch February 1, 2024 14:14
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.

2 participants