From 3929cc891ef72b10605c04f80f58d14c266e2ab7 Mon Sep 17 00:00:00 2001 From: oss-agent-shin Date: Thu, 28 May 2026 00:18:49 -0700 Subject: [PATCH 1/8] fix(proxy/team): clone-on-write shared budget row in _upsert_budget_and_membership (LIT-3359) --- .../management_endpoints/common_utils.py | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/management_endpoints/common_utils.py b/litellm/proxy/management_endpoints/common_utils.py index dc27e87726af..c422398aeaaf 100644 --- a/litellm/proxy/management_endpoints/common_utils.py +++ b/litellm/proxy/management_endpoints/common_utils.py @@ -453,7 +453,31 @@ async def _upsert_budget_and_membership( and existing_budget_id == team_default_budget_id ) + # If multiple memberships still point at this budget row, treat it as + # shared and clone-on-write — otherwise mutating the row here would + # silently move every other member's cap with it (LIT-3359). + shared_with_other_memberships = False if existing_budget_id is not None and not is_shared_default: + try: + membership_refs = await tx.litellm_teammembership.count( + where={"budget_id": existing_budget_id} + ) + shared_with_other_memberships = (membership_refs or 0) > 1 + except Exception as e: + # Refusing to mutate on count failures is safer than risking a + # cross-member overwrite; fall through to the clone-on-write path. + verbose_proxy_logger.debug( + f"_upsert_budget_and_membership: ref-count probe failed for " + f"budget_id={existing_budget_id} (team_id={team_id}, " + f"user_id={user_id}): {e}. Defaulting to clone-on-write." + ) + shared_with_other_memberships = True + + if ( + existing_budget_id is not None + and not is_shared_default + and not shared_with_other_memberships + ): # Update the existing budget in-place to preserve fields not being changed. # Only write fields that the caller explicitly provided (non-None). update_data: Dict[str, Any] = { @@ -483,7 +507,7 @@ async def _upsert_budget_and_membership( # If we're forking off the shared default, seed the new row with the # default's values so fields the caller did not change carry over. - if is_shared_default: + if is_shared_default or shared_with_other_memberships: default_budget_row = await tx.litellm_budgettable.find_unique( where={"budget_id": existing_budget_id} ) From 33514b8f3d196c6b0de7c277f64022aa8c64efb6 Mon Sep 17 00:00:00 2001 From: oss-agent-shin Date: Thu, 28 May 2026 00:18:51 -0700 Subject: [PATCH 2/8] test(proxy/team): cover clone-on-write of shared team-member budget (LIT-3359) --- .../management_endpoints/test_common_utils.py | 196 ++++++++++++++++++ 1 file changed, 196 insertions(+) diff --git a/tests/litellm/proxy/management_endpoints/test_common_utils.py b/tests/litellm/proxy/management_endpoints/test_common_utils.py index f857db770d08..df319a674bdd 100644 --- a/tests/litellm/proxy/management_endpoints/test_common_utils.py +++ b/tests/litellm/proxy/management_endpoints/test_common_utils.py @@ -157,3 +157,199 @@ def test_non_empty_team_member_key_duration_triggers_premium_check( } _update_metadata_fields(updated_kv) mock_check.assert_called() + + +# --------------------------------------------------------------------------- +# Tests for _upsert_budget_and_membership clone-on-write (LIT-3359) +# --------------------------------------------------------------------------- + +from types import SimpleNamespace +from unittest.mock import AsyncMock, MagicMock + +from litellm.proxy._types import UserAPIKeyAuth +from litellm.proxy.management_endpoints.common_utils import ( + _upsert_budget_and_membership, +) + + +def _make_tx(*, ref_count: int, default_budget_fields=None): + """Build a minimal mock prisma transaction with the methods the + function uses: count, update, find_unique, create, upsert.""" + + default_budget_fields = default_budget_fields or { + "budget_id": "shared-bdg-1", + "max_budget": 100.0, + "soft_budget": None, + "max_parallel_requests": None, + "tpm_limit": None, + "rpm_limit": None, + "model_max_budget": None, + "budget_duration": None, + "allowed_models": None, + } + + tx = SimpleNamespace() + tx.litellm_teammembership = SimpleNamespace( + count=AsyncMock(return_value=ref_count), + update=AsyncMock(), + upsert=AsyncMock(), + ) + fake_budget_row = MagicMock() + fake_budget_row.model_dump = MagicMock(return_value=default_budget_fields) + created = SimpleNamespace(budget_id="new-bdg-uuid") + tx.litellm_budgettable = SimpleNamespace( + update=AsyncMock(), + find_unique=AsyncMock(return_value=fake_budget_row), + create=AsyncMock(return_value=created), + ) + return tx + + +@pytest.mark.asyncio +class TestUpsertBudgetMembershipSharedRow: + """LIT-3359: when multiple memberships still point at the same budget_id, + `_upsert_budget_and_membership` MUST clone-on-write — never mutate the + shared row in place.""" + + async def test_shared_row_triggers_clone_on_write(self): + """Two memberships share budget_id -> create new budget, repoint.""" + tx = _make_tx(ref_count=2) + await _upsert_budget_and_membership( + tx, + team_id="t1", + user_id="alice", + max_budget=42.0, + existing_budget_id="shared-bdg-1", + user_api_key_dict=UserAPIKeyAuth(user_id="admin"), + team_default_budget_id=None, + ) + # Must NOT have mutated the shared row in place + tx.litellm_budgettable.update.assert_not_called() + # Must have created a NEW private budget for Alice + tx.litellm_budgettable.create.assert_called_once() + create_data = tx.litellm_budgettable.create.call_args.kwargs["data"] + assert create_data["max_budget"] == 42.0 + # Must have re-linked Alice's membership to the new budget + tx.litellm_teammembership.upsert.assert_called_once() + upsert_kwargs = tx.litellm_teammembership.upsert.call_args.kwargs + assert upsert_kwargs["where"]["user_id_team_id"]["user_id"] == "alice" + assert ( + upsert_kwargs["data"]["update"]["litellm_budget_table"]["connect"][ + "budget_id" + ] + == "new-bdg-uuid" + ) + + async def test_solo_membership_still_updates_in_place(self): + """Single membership owning its budget_id keeps the cheaper in-place + update path (no regression in normal behaviour).""" + tx = _make_tx(ref_count=1) + await _upsert_budget_and_membership( + tx, + team_id="t1", + user_id="alice", + max_budget=42.0, + existing_budget_id="solo-bdg", + user_api_key_dict=UserAPIKeyAuth(user_id="admin"), + team_default_budget_id=None, + ) + tx.litellm_budgettable.update.assert_called_once() + update_args = tx.litellm_budgettable.update.call_args.kwargs + assert update_args["where"]["budget_id"] == "solo-bdg" + assert update_args["data"]["max_budget"] == 42.0 + tx.litellm_budgettable.create.assert_not_called() + tx.litellm_teammembership.upsert.assert_not_called() + + async def test_clone_seeds_unchanged_fields_from_shared_row(self): + """When forking off a shared row, fields the caller did NOT change + (e.g. tpm_limit, allowed_models) must carry over from the shared row + into the new private budget.""" + shared = { + "budget_id": "shared-bdg-2", + "max_budget": 100.0, + "soft_budget": 80.0, + "max_parallel_requests": 5, + "tpm_limit": 1000, + "rpm_limit": 60, + "model_max_budget": {"gpt-4o": 50.0}, + "budget_duration": "30d", + "allowed_models": ["gpt-4o", "claude-3-haiku"], + } + tx = _make_tx(ref_count=3, default_budget_fields=shared) + await _upsert_budget_and_membership( + tx, + team_id="t1", + user_id="alice", + max_budget=42.0, # only changing this + existing_budget_id="shared-bdg-2", + user_api_key_dict=UserAPIKeyAuth(user_id="admin"), + team_default_budget_id=None, + ) + tx.litellm_budgettable.update.assert_not_called() + create_data = tx.litellm_budgettable.create.call_args.kwargs["data"] + # Caller override wins: + assert create_data["max_budget"] == 42.0 + # Carry-over from shared row: + assert create_data["soft_budget"] == 80.0 + assert create_data["max_parallel_requests"] == 5 + assert create_data["tpm_limit"] == 1000 + assert create_data["rpm_limit"] == 60 + assert create_data["budget_duration"] == "30d" + assert create_data["allowed_models"] == ["gpt-4o", "claude-3-haiku"] + assert create_data["model_max_budget"] == {"gpt-4o": 50.0} + + async def test_team_default_match_still_clones(self): + """Pre-existing behaviour: membership pointing at team_default_budget_id + clones-on-write regardless of ref-count.""" + tx = _make_tx(ref_count=1) # only one ref, but it's the team default + await _upsert_budget_and_membership( + tx, + team_id="t1", + user_id="alice", + max_budget=42.0, + existing_budget_id="team-default-bdg", + user_api_key_dict=UserAPIKeyAuth(user_id="admin"), + team_default_budget_id="team-default-bdg", + ) + tx.litellm_budgettable.update.assert_not_called() + tx.litellm_budgettable.create.assert_called_once() + tx.litellm_teammembership.upsert.assert_called_once() + # And we did NOT bother running the ref-count probe in this path + tx.litellm_teammembership.count.assert_not_called() + + async def test_count_probe_failure_defaults_to_clone_on_write(self): + """If the ref-count probe raises, the function must take the safer + clone-on-write branch (never silently fall through to in-place update + of a possibly-shared row).""" + tx = _make_tx(ref_count=1) + tx.litellm_teammembership.count = AsyncMock( + side_effect=RuntimeError("simulated DB failure") + ) + await _upsert_budget_and_membership( + tx, + team_id="t1", + user_id="alice", + max_budget=42.0, + existing_budget_id="some-bdg", + user_api_key_dict=UserAPIKeyAuth(user_id="admin"), + team_default_budget_id=None, + ) + tx.litellm_budgettable.update.assert_not_called() + tx.litellm_budgettable.create.assert_called_once() + + async def test_all_limits_none_still_disconnects(self): + """When every limit is None the function must disconnect the + budget (and not run the ref-count probe at all).""" + tx = _make_tx(ref_count=2) + await _upsert_budget_and_membership( + tx, + team_id="t1", + user_id="alice", + max_budget=None, + existing_budget_id="shared-bdg-1", + user_api_key_dict=UserAPIKeyAuth(user_id="admin"), + team_default_budget_id=None, + ) + tx.litellm_teammembership.update.assert_called_once() + tx.litellm_teammembership.upsert.assert_not_called() + tx.litellm_teammembership.count.assert_not_called() From 4a574d776f83c10a345ed7d600143a9920ee132e Mon Sep 17 00:00:00 2001 From: oss-agent-shin Date: Thu, 28 May 2026 00:29:40 -0700 Subject: [PATCH 3/8] fix(proxy/team): switch shared-budget probe from count to findFirst (LIT-3359, Greptile P2) --- .../management_endpoints/common_utils.py | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/litellm/proxy/management_endpoints/common_utils.py b/litellm/proxy/management_endpoints/common_utils.py index c422398aeaaf..23a6266974f8 100644 --- a/litellm/proxy/management_endpoints/common_utils.py +++ b/litellm/proxy/management_endpoints/common_utils.py @@ -453,21 +453,31 @@ async def _upsert_budget_and_membership( and existing_budget_id == team_default_budget_id ) - # If multiple memberships still point at this budget row, treat it as + # If another membership still points at this budget row, treat it as # shared and clone-on-write — otherwise mutating the row here would # silently move every other member's cap with it (LIT-3359). + # + # We use `findFirst` (excluding the caller's own membership) instead of + # `count`: it stops at the first other reference, so the probe is O(1) + # in the steady-state where each member already has their own budget + # row. The cost is one extra indexed DB roundtrip per non-default + # `/team/member_update` call — accepted as the price of never silently + # overwriting a co-member's cap. shared_with_other_memberships = False if existing_budget_id is not None and not is_shared_default: try: - membership_refs = await tx.litellm_teammembership.count( - where={"budget_id": existing_budget_id} + other_membership = await tx.litellm_teammembership.find_first( + where={ + "budget_id": existing_budget_id, + "NOT": {"user_id": user_id, "team_id": team_id}, + }, ) - shared_with_other_memberships = (membership_refs or 0) > 1 + shared_with_other_memberships = other_membership is not None except Exception as e: - # Refusing to mutate on count failures is safer than risking a + # Refusing to mutate on probe failures is safer than risking a # cross-member overwrite; fall through to the clone-on-write path. verbose_proxy_logger.debug( - f"_upsert_budget_and_membership: ref-count probe failed for " + f"_upsert_budget_and_membership: shared-row probe failed for " f"budget_id={existing_budget_id} (team_id={team_id}, " f"user_id={user_id}): {e}. Defaulting to clone-on-write." ) From 6df668e3ba23fbe64c4e3896a69f34342bc30263 Mon Sep 17 00:00:00 2001 From: oss-agent-shin Date: Thu, 28 May 2026 00:29:42 -0700 Subject: [PATCH 4/8] test(proxy/team): align mock with findFirst probe (LIT-3359) --- .../proxy/management_endpoints/test_common_utils.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/litellm/proxy/management_endpoints/test_common_utils.py b/tests/litellm/proxy/management_endpoints/test_common_utils.py index df319a674bdd..cc835378a88a 100644 --- a/tests/litellm/proxy/management_endpoints/test_common_utils.py +++ b/tests/litellm/proxy/management_endpoints/test_common_utils.py @@ -189,8 +189,11 @@ def _make_tx(*, ref_count: int, default_budget_fields=None): } tx = SimpleNamespace() + # Mock find_first returns a sentinel object iff there is at least one + # OTHER membership pointing at this budget_id (i.e. ref_count >= 2). + other_ref = object() if ref_count >= 2 else None tx.litellm_teammembership = SimpleNamespace( - count=AsyncMock(return_value=ref_count), + find_first=AsyncMock(return_value=other_ref), update=AsyncMock(), upsert=AsyncMock(), ) @@ -315,14 +318,14 @@ async def test_team_default_match_still_clones(self): tx.litellm_budgettable.create.assert_called_once() tx.litellm_teammembership.upsert.assert_called_once() # And we did NOT bother running the ref-count probe in this path - tx.litellm_teammembership.count.assert_not_called() + tx.litellm_teammembership.find_first.assert_not_called() async def test_count_probe_failure_defaults_to_clone_on_write(self): """If the ref-count probe raises, the function must take the safer clone-on-write branch (never silently fall through to in-place update of a possibly-shared row).""" tx = _make_tx(ref_count=1) - tx.litellm_teammembership.count = AsyncMock( + tx.litellm_teammembership.find_first = AsyncMock( side_effect=RuntimeError("simulated DB failure") ) await _upsert_budget_and_membership( @@ -352,4 +355,4 @@ async def test_all_limits_none_still_disconnects(self): ) tx.litellm_teammembership.update.assert_called_once() tx.litellm_teammembership.upsert.assert_not_called() - tx.litellm_teammembership.count.assert_not_called() + tx.litellm_teammembership.find_first.assert_not_called() From fd6e0666ceedb3096fa0f12a1606be84352c8354 Mon Sep 17 00:00:00 2001 From: oss-agent-shin Date: Thu, 28 May 2026 00:48:34 -0700 Subject: [PATCH 5/8] test(proxy/team): mock find_first probe in upsert-budget-membership fixture (LIT-3359) --- .../proxy/common_utils/test_upsert_budget_membership.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_litellm/proxy/common_utils/test_upsert_budget_membership.py b/tests/test_litellm/proxy/common_utils/test_upsert_budget_membership.py index f4bf0d7b2bea..84d387634d02 100644 --- a/tests/test_litellm/proxy/common_utils/test_upsert_budget_membership.py +++ b/tests/test_litellm/proxy/common_utils/test_upsert_budget_membership.py @@ -23,6 +23,10 @@ def mock_tx(): membership = MagicMock() membership.update = AsyncMock() membership.upsert = AsyncMock() + # LIT-3359: default the shared-row probe to "no other reference" so + # tests that exercise the in-place update path are not nudged into + # clone-on-write by an unset mock. + membership.find_first = AsyncMock(return_value=None) # budget “table” budget = MagicMock() From 05df4d6b04ca7013af5798d0270079e344d18856 Mon Sep 17 00:00:00 2001 From: oss-agent-shin Date: Thu, 28 May 2026 00:58:56 -0700 Subject: [PATCH 6/8] test(proxy/team): cover shared-row probe paths in proxy-infra shard (LIT-3359) --- .../test_upsert_budget_membership.py | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/tests/test_litellm/proxy/common_utils/test_upsert_budget_membership.py b/tests/test_litellm/proxy/common_utils/test_upsert_budget_membership.py index 84d387634d02..94d76442156b 100644 --- a/tests/test_litellm/proxy/common_utils/test_upsert_budget_membership.py +++ b/tests/test_litellm/proxy/common_utils/test_upsert_budget_membership.py @@ -373,3 +373,81 @@ async def test_upsert_updates_in_place_when_member_has_private_budget( ) mock_tx.litellm_budgettable.create.assert_not_called() mock_tx.litellm_teammembership.upsert.assert_not_called() + + +# --------------------------------------------------------------------------- +# LIT-3359 coverage: shared-row probe paths (these mirror the dedicated +# tests under tests/litellm/proxy/management_endpoints/test_common_utils.py +# but live in the proxy-infra shard so codecov sees the new branches in +# common_utils.py exercised here too). +# --------------------------------------------------------------------------- + + +@pytest.mark.asyncio +async def test_upsert_clones_when_budget_id_is_shared_with_other_membership( + mock_tx, fake_user +): + """LIT-3359: if find_first returns a sibling membership, we clone-on-write.""" + sibling = types.SimpleNamespace(user_id="bob", team_id="team-shared", + budget_id="shared-bdg") + mock_tx.litellm_teammembership.find_first = AsyncMock(return_value=sibling) + # Seed the shared row find_unique returns (used to carry-over fields) + shared_row = MagicMock() + shared_row.model_dump = MagicMock(return_value={ + "budget_id": "shared-bdg", + "max_budget": 100.0, + "tpm_limit": None, + "rpm_limit": None, + "soft_budget": None, + "max_parallel_requests": None, + "model_max_budget": None, + "budget_duration": None, + "allowed_models": None, + }) + mock_tx.litellm_budgettable.find_unique = AsyncMock(return_value=shared_row) + + await _upsert_budget_and_membership( + mock_tx, + team_id="team-shared", + user_id="alice", + max_budget=42.0, + existing_budget_id="shared-bdg", + user_api_key_dict=fake_user, + team_default_budget_id=None, + ) + + # MUST NOT have mutated the shared row in place + mock_tx.litellm_budgettable.update.assert_not_called() + # MUST have created a new private budget + mock_tx.litellm_budgettable.create.assert_awaited_once() + create_kwargs = mock_tx.litellm_budgettable.create.await_args.kwargs + assert create_kwargs["data"]["max_budget"] == 42.0 + # MUST have re-linked the caller's membership to the new budget + mock_tx.litellm_teammembership.upsert.assert_awaited_once() + + +@pytest.mark.asyncio +async def test_upsert_probe_failure_falls_through_to_clone(mock_tx, fake_user): + """LIT-3359: if find_first itself raises, we DEFAULT to clone-on-write + rather than risk mutating a possibly-shared row.""" + mock_tx.litellm_teammembership.find_first = AsyncMock( + side_effect=RuntimeError("boom") + ) + shared_row = MagicMock() + shared_row.model_dump = MagicMock(return_value={"budget_id": "x", + "max_budget": 50.0}) + mock_tx.litellm_budgettable.find_unique = AsyncMock(return_value=shared_row) + + await _upsert_budget_and_membership( + mock_tx, + team_id="t", + user_id="u", + max_budget=7.0, + existing_budget_id="x", + user_api_key_dict=fake_user, + team_default_budget_id=None, + ) + + # safety: clone-on-write, NOT in-place + mock_tx.litellm_budgettable.update.assert_not_called() + mock_tx.litellm_budgettable.create.assert_awaited_once() From bedcfb487649c1a0cc84fd857601aba7279261a4 Mon Sep 17 00:00:00 2001 From: oss-agent-shin Date: Thu, 28 May 2026 01:08:37 -0700 Subject: [PATCH 7/8] refactor(proxy/team): collapse multi-line probe call to single statement (LIT-3359) --- .../management_endpoints/common_utils.py | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/litellm/proxy/management_endpoints/common_utils.py b/litellm/proxy/management_endpoints/common_utils.py index 23a6266974f8..1a30e75c6b36 100644 --- a/litellm/proxy/management_endpoints/common_utils.py +++ b/litellm/proxy/management_endpoints/common_utils.py @@ -455,9 +455,8 @@ async def _upsert_budget_and_membership( # If another membership still points at this budget row, treat it as # shared and clone-on-write — otherwise mutating the row here would - # silently move every other member's cap with it (LIT-3359). - # - # We use `findFirst` (excluding the caller's own membership) instead of + # silently move every other member's cap with it (LIT-3359). We use + # `find_first` (excluding the caller's own membership) instead of # `count`: it stops at the first other reference, so the probe is O(1) # in the steady-state where each member already has their own budget # row. The cost is one extra indexed DB roundtrip per non-default @@ -466,21 +465,12 @@ async def _upsert_budget_and_membership( shared_with_other_memberships = False if existing_budget_id is not None and not is_shared_default: try: - other_membership = await tx.litellm_teammembership.find_first( - where={ - "budget_id": existing_budget_id, - "NOT": {"user_id": user_id, "team_id": team_id}, - }, - ) + _probe_where = {"budget_id": existing_budget_id, "NOT": {"user_id": user_id, "team_id": team_id}} + other_membership = await tx.litellm_teammembership.find_first(where=_probe_where) shared_with_other_memberships = other_membership is not None except Exception as e: - # Refusing to mutate on probe failures is safer than risking a - # cross-member overwrite; fall through to the clone-on-write path. - verbose_proxy_logger.debug( - f"_upsert_budget_and_membership: shared-row probe failed for " - f"budget_id={existing_budget_id} (team_id={team_id}, " - f"user_id={user_id}): {e}. Defaulting to clone-on-write." - ) + # Refuse to mutate on probe failures; fall through to clone-on-write. + verbose_proxy_logger.debug("_upsert_budget_and_membership: shared-row probe failed for budget_id=%s (team_id=%s, user_id=%s): %s. Defaulting to clone-on-write.", existing_budget_id, team_id, user_id, e) shared_with_other_memberships = True if ( From f421d2bba56b74611e1065781140dbc8a3df293b Mon Sep 17 00:00:00 2001 From: oss-agent-shin Date: Thu, 28 May 2026 01:12:20 -0700 Subject: [PATCH 8/8] style(proxy/team): black-format shared-row probe block (LIT-3359) --- .../proxy/management_endpoints/common_utils.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/litellm/proxy/management_endpoints/common_utils.py b/litellm/proxy/management_endpoints/common_utils.py index 1a30e75c6b36..2cc72d46e368 100644 --- a/litellm/proxy/management_endpoints/common_utils.py +++ b/litellm/proxy/management_endpoints/common_utils.py @@ -465,12 +465,23 @@ async def _upsert_budget_and_membership( shared_with_other_memberships = False if existing_budget_id is not None and not is_shared_default: try: - _probe_where = {"budget_id": existing_budget_id, "NOT": {"user_id": user_id, "team_id": team_id}} - other_membership = await tx.litellm_teammembership.find_first(where=_probe_where) + _probe_where = { + "budget_id": existing_budget_id, + "NOT": {"user_id": user_id, "team_id": team_id}, + } + other_membership = await tx.litellm_teammembership.find_first( + where=_probe_where + ) shared_with_other_memberships = other_membership is not None except Exception as e: # Refuse to mutate on probe failures; fall through to clone-on-write. - verbose_proxy_logger.debug("_upsert_budget_and_membership: shared-row probe failed for budget_id=%s (team_id=%s, user_id=%s): %s. Defaulting to clone-on-write.", existing_budget_id, team_id, user_id, e) + verbose_proxy_logger.debug( + "_upsert_budget_and_membership: shared-row probe failed for budget_id=%s (team_id=%s, user_id=%s): %s. Defaulting to clone-on-write.", + existing_budget_id, + team_id, + user_id, + e, + ) shared_with_other_memberships = True if (