aipotheosis-labs / aipotheosis-labs/aci
Issue when adding multiple linked account on a single linked owner account ID
- Vorherrschende Sprache
- Python
- Sterne
- 4.9k
- Forks
- 484
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
### Required Pre-requisites
- [x] I have read the [Documentation](https://www.aci.dev/docs)
- [x] I have searched the [Issue Tracker](https://github.com/aipotheosis-labs/aci/issues) and [Discussions](https://github.com/aipotheosis-labs/aci/discussions) that this hasn't been reported yet.
- [x] Consider asking in [Discussions](https://github.com/aipotheosis-labs/aci/discussions) first
### Description
```{"level": "ERROR", "timestamp": "2025-05-22 07:39:25,653", "file": "aci.server.middleware.interceptor", "message": "Multiple rows were found when one or none was required", "exc_info": "Traceback (most recent call last):\n File \"/workdir/.venv/lib/python3.12/site-packages/starlette/middleware/base.py\", line 148, in call_next\n message = await recv_stream.receive()\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/workdir/.venv/lib/python3.12/site-packages/anyio/streams/memory.py\", line 126, in receive\n raise EndOfStream from None\nanyio.EndOfStream\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/workdir/aci/server/middleware/interceptor.py\", line 37, in dispatch\n response = await call_next(request)\n ^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/workdir/.venv/lib/python3.12/site-packages/starlette/middleware/base.py\", line 156, in call_next\n raise app_exc\n File \"/workdir/.venv/lib/python3.12/site-packages/starlette/middleware/base.py\", line 141, in coro\n await self.app(scope, receive_or_disconnect, send_no_error)\n File \"/workdir/.venv/lib/python3.12/site-packages/starlette/middleware/cors.py\", line 93, in __call__\n await self.simple_response(scope, receive, send, request_headers=headers)\n File \"/workdir/.venv/lib/python3.12/site-packages/starlette/middleware/cors.py\", line 144, in simple_response\n await self.app(scope, receive, send)\n File \"/workdir/.venv/lib/python3.12/site-packages/starlette/middleware/sessions.py\", line 85, in __call__\n await self.app(scope, receive, send_wrapper)\n File \"/workdir/.venv/lib/python3.12/site-packages/starlette/middleware/base.py\", line 176, in __call__\n with recv_stream, send_stream, collapse_excgroups():\n ^^^^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.12/contextlib.py\", line 158, in __exit__\n self.gen.throw(value)\n File \"/workdir/.venv/lib/python3.12/site-packages/starlette/_utils.py\", line 82, in collapse_excgroups\n raise exc\n File \"/workdir/.venv/lib/python3.12/site-packages/starlette/middleware/base.py\", line 178, in __call__\n response = await self.dispatch_func(request, call_next)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/workdir/aci/server/middleware/ratelimit.py\", line 48, in dispatch\n response = await call_next(request)\n ^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/workdir/.venv/lib/python3.12/site-packages/starlette/middleware/base.py\", line 156, in call_next\n raise app_exc\n File \"/workdir/.venv/lib/python3.12/site-packages/starlette/middleware/base.py\", line 141, in coro\n await self.app(scope, receive_or_disconnect, send_no_error)\n File \"/workdir/.venv/lib/python3.12/site-packages/starlette/middleware/exceptions.py\", line 62, in __call__\n await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)\n File \"/workdir/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py\", line 53, in wrapped_app\n raise exc\n File \"/workdir/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py\", line 42, in wrapped_app\n await app(scope, receive, sender)\n File \"/workdir/.venv/lib/python3.12/site-packages/starlette/routing.py\", line 714, in __call__\n await self.middleware_stack(scope, receive, send)\n File \"/workdir/.venv/lib/python3.12/site-packages/starlette/routing.py\", line 734, in app\n await route.handle(scope, receive, send)\n File \"/workdir/.venv/lib/python3.12/site-packages/starlette/routing.py\", line 288, in handle\n await self.app(scope, receive, send)\n File \"/workdir/.venv/lib/python3.12/site-packages/starlette/routing.py\", line 76, in app\n await wrap_app_handling_exceptions(app, request)(scope, receive, send)\n File \"/workdir/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py\", line 53, in wrapped_app\n raise exc\n File \"/workdir/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py\", line 42, in wrapped_app\n await app(scope, receive, sender)\n File \"/workdir/.venv/lib/python3.12/site-packages/starlette/routing.py\", line 73, in app\n response = await f(request)\n ^^^^^^^^^^^^^^^^\n File \"/workdir/.venv/lib/python3.12/site-packages/fastapi/routing.py\", line 301, in app\n raw_response = await run_endpoint_function(\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/workdir/.venv/lib/python3.12/site-packages/fastapi/routing.py\", line 212, in run_endpoint_function\n return await dependant.call(**values)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/workdir/aci/server/routes/linked_accounts.py\", line 221, in link_account_with_no_auth\n quota_manager.enforce_linked_accounts_creation_quota(\n File \"/workdir/aci/server/quota_manager.py\", line 91, in enforce_linked_accounts_creation_quota\n if crud.linked_accounts.linked_account_owner_id_exists_in_org(\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/workdir/aci/common/db/crud/linked_accounts.py\", line 197, in linked_account_owner_id_exists_in_org\n return db_session.execute(statement).scalar_one_or_none() is not None\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/workdir/.venv/lib/python3.12/site-packages/sqlalchemy/engine/result.py\", line 1485, in scalar_one_or_none\n return self._only_one_row(\n ^^^^^^^^^^^^^^^^^^^\n File \"/workdir/.venv/lib/python3.12/site-packages/sqlalchemy/engine/result.py\", line 805, in _only_one_row\n raise exc.MultipleResultsFound(\nsqlalchemy.exc.MultipleResultsFound: Multiple rows were found when one or none was required", "duration": 0.057191, "request_id": "31e13793-a225-4934-a964-98373f60f76c"}```
This the error i got. And the reason why i got this error is because i have tried to link multiple accounts with a multiple linked owner ID. so, I have made a quick fix on ```aci/common/db/crud/linked_accounts.py``` in function:
```python
def linked_account_owner_id_exists_in_org(
db_session: Session, org_id: UUID, linked_account_owner_id: str
) -> bool:
statement = select(LinkedAccount).filter(
LinkedAccount.linked_account_owner_id == linked_account_owner_id,
LinkedAccount.project_id.in_(select(Project.id).filter(Project.org_id == org_id)),
)
return len(list(db_session.execute(statement).scalars().all())) > 0
```
But it is a temp fix based on my use case sometime if anyone has single owner with multiple linked accounts and i dont think so it will work
### Additional context
_No response_
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.