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

[Vocabularies] Create new async Vocabularies resource, service & REST… #2816

Merged
merged 10 commits into from
Feb 4, 2025

Conversation

jerome-poisson
Copy link
Contributor

… API.

SDESK-7468

@jerome-poisson
Copy link
Contributor Author

Not fully finished, I have a few points that I need to check (see FIXME).

Copy link
Contributor

@MarkLark86 MarkLark86 left a comment

Choose a reason for hiding this comment

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

There are a couple more tasks that are left here, such as creating the module, registering the resource, disabling the REST API from old resource service, and updating the default_settings.MODULE.

See the docs or this PR for an example

Copy link
Contributor

@MarkLark86 MarkLark86 left a comment

Choose a reason for hiding this comment

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

Model looks good to me, just a couple improvement suggestions

superdesk/vocabularies/async_vocabularies.py Outdated Show resolved Hide resolved
superdesk/vocabularies/async_vocabularies.py Outdated Show resolved Hide resolved
superdesk/vocabularies/async_vocabularies.py Outdated Show resolved Hide resolved
superdesk/vocabularies/async_vocabularies.py Outdated Show resolved Hide resolved
@jerome-poisson
Copy link
Contributor Author

@MarkLark86 thanks for your feedbacks, I should have addressed all of them, let me know if it's fine now.

- Moved to `vocabularies_async` and `types` to be consistent with `dev_async`.
- Set `internal_resource` to the old resource.
- Added `ResourceConfig`.
- Added module to `default_settings`.
- Addressed feedbacks.
@jerome-poisson
Copy link
Contributor Author

My resource doesn't appear in the client, I'm not sure why.
Also, how are we supposed to convert privilege?

privileges = {"PATCH": "vocabularies", "POST": "vocabularies", "DELETE": "vocabularies"}

@MarkLark86
Copy link
Contributor

My resource doesn't appear in the client, I'm not sure why.

I'm guessing the client is using the home endpoint to get the list of endpoints, and using that. This endpoint is populated by eve. I will look into adding our async resources to that home endpoint. I will comment here once that's done

Also, how are we supposed to convert privilege?

privileges = {"PATCH": "vocabularies", "POST": "vocabularies", "DELETE": "vocabularies"}

Helmy has just created a PR to add this functionality. For now, we can leave auth out of this resource until the auth rule PR is merged.

@MarkLark86
Copy link
Contributor

@jerome-poisson I have updated your PR in your branch, to get the REST API working, along with a couple other fixes (like auth fix, cors headers and a couple issues in the model & service).

It works locally, except I am unable to edit an existing CV. I haven't done thorough testing there, but looks like from the front-end it's trying to use POST instead of PATCH when updating an existing item. Can you please investigate and find a solution

@jerome-poisson
Copy link
Contributor Author

@MarkLark86 Sure, I'll investigate that. Thanks for your review and patches.

update.unique_field = "qcode"

unique_field = update.unique_field
vocabs = {}
if update.schema_ and update.items:
if update.schema and update.items:
Copy link
Contributor Author

@jerome-poisson jerome-poisson Jan 28, 2025

Choose a reason for hiding this comment

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

I did use schema_ because schema is already used in ResourceModel (it's coming from Pydantic's BaseModel). With your change, I have that:

/home/goffi/dev/sourcefabric/venv/async_3.10/lib/python3.10/site-packages/pydantic/_internal/_fields.py:172: UserWarning: Field name "schema" in "VocabulariesResourceModel" shadows an attribute in parent "ResourceModel"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm reverting to schema_ and using:

schema_: Annotated[dict[str, dict], Field(alias="schema")]

@jerome-poisson
Copy link
Contributor Author

I still can't run the client at all, I have this message in JS console:

Uncaught (in promise) 
Object { status: 404, resource: "vocabularies" }

And I can't even log in (in fact, I don't have logging screen at all).

If you could run the frontend with this PR I must have something wrong in my config or something, I'm investigating.

@@ -414,6 +416,24 @@ def setup_sentry(self):

sentry_sdk.init(dsn=self.config["SENTRY_DSN"], integrations=[QuartIntegration(), AsyncioIntegration()])

def extend_eve_home_endpoint(self, links: list[dict]) -> None:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method is never called.

Copy link
Contributor

Choose a reason for hiding this comment

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

You'll need to grab latest eve lib (from our superdesk/eve/Async repo & branch)

@jerome-poisson
Copy link
Contributor Author

@MarkLark86 the client is using a wrong HTTP verb due to the _links field missing, it was done in older Resource with build_custom_hateoas at https://github.com/superdesk/superdesk-core/blob/develop/superdesk/resource.py#L44 .

@jerome-poisson
Copy link
Contributor Author

_links field depends on the work currently done by @eos87 , so I'm merging current PR.

@jerome-poisson jerome-poisson merged commit c39fc7c into superdesk:async Feb 4, 2025
7 of 16 checks passed
@jerome-poisson jerome-poisson deleted the SDESK-7468 branch February 4, 2025 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants