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

[PLAT-4257] - return results from committing a transaction #157

Merged
merged 2 commits into from
Jun 26, 2023

Conversation

noahgorstein
Copy link
Member

Adds a response to the commit method. There is some helpful information in that response like the number of triples added/removed in that transaction.

Example usage:

    result = conn.commit()

    print(f"Triples added: {result["added"]}")
    print(f"Triples removed: {result["removed"]}")

self.transaction = None

return resp.json()
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we put this on a try block? I know we don't do this for a majority of the code, but I just ran into that thought. what if the request fails, and resp no longer has the .json() method?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think if the request fails, a StardogException should be raised iiuc. client.post:

def post(self, path, **kwargs):
return self.__wrap(self.session.post(self.url + path, **kwargs))

returns the result from client.__wrap which should check if the request failed and raise an exception:

def __wrap(self, request):

I think that's the order of execution but I might be misunderstanding/missing something.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, I believe Noah is right. __wrap should handle a failed request and then throwing the exception

Copy link
Collaborator

Choose a reason for hiding this comment

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

right, I forgot about it.

Copy link
Collaborator

@scardena scardena left a comment

Choose a reason for hiding this comment

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

looks good, just added one question

self.transaction = None

return resp.json()
Copy link
Contributor

Choose a reason for hiding this comment

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

yes, I believe Noah is right. __wrap should handle a failed request and then throwing the exception

@noahgorstein noahgorstein merged commit 1531ea2 into main Jun 26, 2023
@noahgorstein noahgorstein deleted the feature/PLAT-4257-add-json-to-commit-return branch June 26, 2023 20:58
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.

3 participants