Skip to content

Can't toggle remaining models on space when a model gets disabled at organization level #9

Open
@axelander

Description

@axelander

Issue

Model A and B are enabled for an organization. A space in the org has both of the models enabled. When model A is deactivated for the organization, you can no longer toggle any of the other models on/off on the space.
The setter for completion/embedding models on the space-model validates that the space can access the model (https://github.com/inooLabs/intric-release/blob/main/backend/src/instorage/spaces/space.py#L202-L218), which it no longer can.

Would it make sense to remove the setter validation to allow spaces to keep settings for currently inaccessible models?

Example test that verifies the behaviour

async def test_update_space_with_inaccessible_models_raises_unauthorized(service: SpaceService):
    """
    Test that validates that the behavior of updating a space with inaccessible models raises UnauthorizedException.
    TODO: Verify that this is not a bug. When a model is deactivated on the organization and still activated on a space, the space can not toggle any of the other models.
    """
    # Create a real Space instance
    space = Space(
        id=TEST_UUID,
        tenant_id=TEST_UUID,
        user_id=None,
        name="Test Space",
        description=None,
        embedding_models=[],
        completion_models=[],
        assistants=[],
        services=[],
        websites=[],
        groups=[],
        members={TEST_USER.id: MagicMock(role=SpaceRole.ADMIN)},
    )

    # Create a mix of accessible and inaccessible models
    accessible_model = MagicMock(can_access=True, id=uuid4())
    inaccessible_model = MagicMock(can_access=False, id=uuid4())
    models = [accessible_model, inaccessible_model]

    service.get_space = AsyncMock(return_value=space)
    service.ai_models_service.get_completion_models = AsyncMock(return_value=models)

    # Verify that attempting to update with inaccessible models raises UnauthorizedException
    with pytest.raises(UnauthorizedException):
        await service.update_space(
            id=TEST_UUID,
            completion_model_ids=[accessible_model.id, inaccessible_model.id]
        )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions