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

implement 'list_projects' with the org access feature #825

Merged
merged 3 commits into from
Dec 16, 2024

Conversation

alexey-cord-tech
Copy link
Contributor

@alexey-cord-tech alexey-cord-tech commented Dec 13, 2024

Introduction and Explanation

Next step towards org-wide access: projects.

Unfortunately we're "doing too much" in project listing, and doing this within the confines of the old get_projects was not feasible (would have to fetch a lot of data potentially, with the label rows and editors and stuff).

So I'm adding the new list_projects instead, with a nicer API; also doing lots of unrelated-ish refactorings/cleanups because I initially attempted to do it backwards-compatibly.

Documentation

Docstrings; the main docs to be written

Tests

Coming in the BE PR https://github.com/encord-team/cord-backend/pull/4431

Known issues

This is so hairy and took me 10x the estimated time :/

Copy link

github-actions bot commented Dec 13, 2024

Unit test report ((Pydantic 2.x)

193 tests   193 ✅  6s ⏱️
  1 suites    0 💤
  1 files      0 ❌

Results for commit 24da0e4.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Dec 13, 2024

Unit test report (Pydantic 1.x)

193 tests   193 ✅  6s ⏱️
  1 suites    0 💤
  1 files      0 ❌

Results for commit 24da0e4.

♻️ This comment has been updated with latest results.

@@ -1139,6 +1139,7 @@ def list_project_datasets(self, project_hash: UUID) -> Iterable[ProjectDataset]:
.results
)

@deprecated("0.1.102", alternative="encord.ontology.Ontology class")
Copy link
Contributor

Choose a reason for hiding this comment

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

Noice

encord/user_client.py Outdated Show resolved Hide resolved
@@ -117,21 +118,38 @@ def ontology(self) -> Dict[str, Any]:
This method returns the same structure as :meth:`encord.Project.ontology_structure`, just in
raw python dictionary format.
"""
return self._ontology.structure.to_dict()
return self._ontology_instance.structure.to_dict()
Copy link
Contributor

Choose a reason for hiding this comment

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

In a non-ideal scenario when the customer relies on _ontology, they'll get exception when trying to call methods from None object. I guess we should expose _ontology property and rename the private attribute to something like __lazy_load_ontology so at least it wouldn't break crazy use cases

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a fair point but I think that we can probably change the private internals without it being too much of an issue. Have we checked that all of our private code doesn't use _ontology directly? Need to ensure that we don't attempt to actually use it in label parsing for example and we haven't initialised it?

E.G: Can we ensure that we have always fetched the Ontology before we attempt to parse label blobs?

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 think it's totally fair to break backwards compat in underscore-prefix parts.

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1, that's not a part of the public interface, so no problem here.
And this method is deprecated for more than a year anyways.

Copy link
Contributor

@Jim-Encord Jim-Encord left a comment

Choose a reason for hiding this comment

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

Looks scary but correct

yield Project(
client=client,
project_instance=row,
ontology=None, # lazy-load
Copy link
Contributor

Choose a reason for hiding this comment

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

Damn, crazy approach. Is it worth writing a test checking that this method does atmost 2-3 network calls and codify this solution?

Copy link
Contributor Author

@alexey-cord-tech alexey-cord-tech Dec 16, 2024

Choose a reason for hiding this comment

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

Well on dev the list_projects returns a few tens of thousand items ;), so with a non-lazy version this test took forever. So we kind of have this by accident.

We can probably make this a unit test, but it's not super easy to write...

@@ -117,21 +118,38 @@ def ontology(self) -> Dict[str, Any]:
This method returns the same structure as :meth:`encord.Project.ontology_structure`, just in
raw python dictionary format.
"""
return self._ontology.structure.to_dict()
return self._ontology_instance.structure.to_dict()
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a fair point but I think that we can probably change the private internals without it being too much of an issue. Have we checked that all of our private code doesn't use _ontology directly? Need to ensure that we don't attempt to actually use it in label parsing for example and we haven't initialised it?

E.G: Can we ensure that we have always fetched the Ontology before we attempt to parse label blobs?

Copy link
Collaborator

@sergei-encord sergei-encord left a comment

Choose a reason for hiding this comment

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

Looks great. One comment on the workflow_manager_uuid getter interface change

@alexey-cord-tech alexey-cord-tech merged commit 3897f76 into master Dec 16, 2024
5 of 6 checks passed
@alexey-cord-tech alexey-cord-tech deleted the ak/projects-org-wide-access branch December 16, 2024 17:15
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.

4 participants