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

Support collections editing and new DS type #43

Merged
merged 5 commits into from
Jan 12, 2024
Merged

Support collections editing and new DS type #43

merged 5 commits into from
Jan 12, 2024

Conversation

blokhin
Copy link
Member

@blokhin blokhin commented Dec 14, 2023

@knopki client.v0.collections.create() also supports editing the existing collections (the id has to be supplied), see https://github.com/basf/metis-bff/blob/f6f73257d6f2603496118676969663e4d6e4deaa/routes/%5Bversion%5D/collections/_helpers.js#L65

However here is a caveat: 3 kwargs typeId, dataSources, and users are mapped onto type_id, data_source_ids, and user_ids (note camel case vs. snake case) which prevents me from doing client.v0.collections.create(**dict(metis_collection_changed)). I assume, the MetisCollectionCreateDTO should be upgraded for that, right?

@blokhin blokhin added the enhancement New feature or request label Dec 14, 2023
@blokhin blokhin requested a review from knopki December 14, 2023 00:52
@blokhin
Copy link
Member Author

blokhin commented Dec 14, 2023

TODO setting id=None for creating a new collection

@pep8speaks
Copy link

pep8speaks commented Dec 14, 2023

Hello @blokhin! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2024-01-12 20:05:28 UTC

Copy link
Member

@knopki knopki left a comment

Choose a reason for hiding this comment

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

Overall, it's good PR. But fix style, please.

metis_client/dtos/collection.py Outdated Show resolved Hide resolved
metis_client/dtos/collection.py Outdated Show resolved Hide resolved
@@ -18,16 +18,16 @@


class DataSourceType(int, Enum):
"Data source types"

Copy link
Member

Choose a reason for hiding this comment

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

Why docstring remove?

Copy link
Member Author

Choose a reason for hiding this comment

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

because it doesn’t bring any valuable information here

Copy link
Member

Choose a reason for hiding this comment

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

Correct. So there are two ways to go about it: write valuable docstring or turn off the linter rule missing-class-docstring.

metis_client/namespaces/v0_collections.py Outdated Show resolved Hide resolved
@knopki
Copy link
Member

knopki commented Dec 15, 2023

However here is a caveat: 3 kwargs typeId, dataSources, and users are mapped onto type_id, data_source_ids, and user_ids (note camel case vs. snake case) which prevents me from doing client.v0.collections.create(**dict(metis_collection_changed)). I assume, the MetisCollectionCreateDTO should be upgraded for that, right?

Or MetisCollectionsCreateKwargs and create_event(...)? Snake case looks like a bug.

@blokhin
Copy link
Member Author

blokhin commented Dec 15, 2023

The different case originates from the BFF API, which being in JavaScript contradicts Python style. How could we map fields nicely onto each other so that one doesn’t have to copy them manually? Maybe to implement constructor for the typed dict?

@knopki
Copy link
Member

knopki commented Dec 15, 2023

BFF API already mapped (manually) to Python-style DTOs in client code. Why copy manually?

Maybe to implement constructor for the typed dict?

TypedDict classes can contain only type annotation. TypedDict is a thin type. If you need a constructor or an additional method of a class or instance, it is better to use dataclass.

@blokhin
Copy link
Member Author

blokhin commented Dec 15, 2023

BFF API already mapped (manually) to Python-style DTOs in client code. Why copy manually?

Nope. Otherwise as said I would be able to do client.v0.collections.create(**dict(metis_collection_changed)) but now it’s impossible. So I have to do metis_collection_changed["type_id"] = metis_collection_changed["typeId"] etc.

@blokhin
Copy link
Member Author

blokhin commented Jan 11, 2024

@knopki how do I better implement client.v0.collections.create(**dict(metis_collection_changed)) ?

@knopki
Copy link
Member

knopki commented Jan 12, 2024

@knopki how do I better implement client.v0.collections.create(**dict(metis_collection_changed)) ?

I recommend correcting the stylistic errors in this PR (black, pylint) and merge it. Then discuss the problem with dictionaries, as it can be quite large.

@blokhin blokhin merged commit af003bd into master Jan 12, 2024
5 of 7 checks passed
@delete-merged-branch delete-merged-branch bot deleted the edit-colls branch January 12, 2024 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants