Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

Conversation

@InnocentBug
Copy link

A common situation for my developing with the SDK that, I don't know if a node exists or not.

For example, a script that adds a Material to a collection, might create the collection first, but with the second material that the Collection node exists already.
Or citing a paper, a different user might have added the reference already.

For these situations it would be nice to catch the exception and fetch the existing node instead.
(Or course, this has to be used with a bit of care to not overwrite or use false duplicate nodes.)

So this would be ideal:

try:
       ref = cript.Reference(title="Title, doi="10.1039/D2ME00137C",  authors=["Schneider, Ludwig"])
except  cript.data_model.exceptions.UniqueNodeError as exc:
      ref = cript.Reference.get(exc.existing_url)

This requires that the UniqueNodeError transparently makes the found url accessible.
In this PR, I simply parse the URL from the message and make it available.

As a precaution for changing message, I issue warnings if no such URL can be found.

@InnocentBug InnocentBug added the enhancement New feature or request label Dec 1, 2022
@InnocentBug InnocentBug self-assigned this Dec 1, 2022
@InnocentBug
Copy link
Author

I also have false positive file changes, that black detected in the CodeBase.

We should really have an auto-formatter for this repo to avoid this.

Here it was black.

We could setup a pre-commit bot.
Or even, better, I recommend trunk.io.

Trunk is free for open-source, and I could set it up for us if desired.

@dylanwal dylanwal merged commit 10050f1 into develop Dec 1, 2022
@dylanwal dylanwal deleted the improve-unq-node-exc branch December 1, 2022 19:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants