diff --git a/src/lightning/app/utilities/cloud.py b/src/lightning/app/utilities/cloud.py index 042369aa2f5ee..520e2e6a14b90 100644 --- a/src/lightning/app/utilities/cloud.py +++ b/src/lightning/app/utilities/cloud.py @@ -30,7 +30,9 @@ def _get_project(client: LightningClient, organization_id: Optional[str] = None, if organization_id is None: organization_id = constants.LIGHTNING_CLOUD_ORGANIZATION_ID - projects = client.projects_service_list_memberships(organization_id=organization_id) + projects = client.projects_service_list_memberships( + **({"organization_id": organization_id} if organization_id is not None else {}) + ) if project_id is not None: for membership in projects.memberships: if membership.project_id == project_id: diff --git a/tests/tests_app/utilities/test_cloud.py b/tests/tests_app/utilities/test_cloud.py index 8d3cc8a941447..08196b06fca07 100644 --- a/tests/tests_app/utilities/test_cloud.py +++ b/tests/tests_app/utilities/test_cloud.py @@ -17,6 +17,15 @@ def test_get_project_picks_up_organization_id(): lightning_client.projects_service_list_memberships.assert_called_once_with(organization_id="organization_id") +def test_get_project_doesnt_pass_organization_id_if_its_not_set(): + lightning_client = LightningClient() + lightning_client.projects_service_list_memberships = mock.MagicMock( + return_value=V1ListMembershipsResponse(memberships=[V1Membership(project_id="project_id")]), + ) + _get_project(lightning_client) + lightning_client.projects_service_list_memberships.assert_called_once_with() + + def test_is_running_cloud(): """We can determine if Lightning is running in the cloud.""" with mock.patch.dict(os.environ, {}, clear=True):