Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/changelog/next_release/55.bugfix.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
When updating a connection type, it is prohibited to update it if there is a transfer associated with this connection
Prohibit updating connection type it if there is a transfer associated with this connection
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ python-multipart = { version = "^0.0.9", optional = true }
celery = { version = "^5.3.3", optional = true }
onetl = { version = "^0.10.2", extras = ["spark"], optional = true }
psycopg2-binary = { version = "^2.9.7", optional = true }
mypy = "^1.10.0"

[tool.poetry.extras]
backend = [
Expand Down Expand Up @@ -102,13 +101,11 @@ gevent = "^24.2.1"

[tool.poetry.group.dev.dependencies]
pre-commit = "^3.3.3"
mypy = "^1.4.1"
Comment thread
dolfinus marked this conversation as resolved.
black = "^24.3.0"
isort = "^5.12.0"
flake8 = "^7.0.0"
bandit = "^1.7.5"
platformdirs = "4.2.2"
sqlalchemy = {extras = ["mypy"], version = "^2.0.18"}
Comment thread
dolfinus marked this conversation as resolved.
types-python-jose = "^3.3.4.7"

[tool.poetry.group.docs.dependencies]
Expand Down
12 changes: 9 additions & 3 deletions syncmaster/backend/api/v1/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

from syncmaster.backend.api.deps import UnitOfWorkMarker
from syncmaster.backend.services import UnitOfWork, get_user
from syncmaster.db.models import Transfer, User
from syncmaster.db.models import Connection, Transfer, User
from syncmaster.db.utils import Permission
from syncmaster.exceptions import ActionNotAllowedError
from syncmaster.exceptions.connection import (
ConnectionDeleteError,
ConnectionNotFoundError,
ConnectionTypeUpdateError,
)
from syncmaster.exceptions.credentials import AuthDataNotFoundError
from syncmaster.exceptions.group import GroupNotFoundError
Expand Down Expand Up @@ -181,12 +182,17 @@ async def update_connection(

async with unit_of_work:
linked_transfers: Sequence[Transfer] = await unit_of_work.transfer.list_by_connection_id(connection_id)
connection: Connection = await unit_of_work.connection.read_by_id(connection_id=connection_id)
data = changes.data.dict(exclude={"auth_data"}) if changes.data else {}
if data.get("type", None) is not None:
if data["type"] != connection.data["type"]:
if linked_transfers:
Comment thread
dmitry-pedchenko marked this conversation as resolved.
raise ConnectionTypeUpdateError
connection = await unit_of_work.connection.update(
connection_id=connection_id,
name=changes.name,
description=changes.description,
data=changes.data.dict(exclude={"auth_data"}) if changes.data else {},
linked_transfers=linked_transfers,
data=data,
)

if changes.auth_data:
Expand Down
9 changes: 1 addition & 8 deletions syncmaster/db/repositories/connection.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
# SPDX-FileCopyrightText: 2023-2024 MTS (Mobile Telesystems)
# SPDX-License-Identifier: Apache-2.0
from collections.abc import Sequence
from typing import Any, NoReturn

from sqlalchemy import ScalarResult, insert, select
from sqlalchemy.exc import DBAPIError, IntegrityError, NoResultFound
from sqlalchemy.ext.asyncio import AsyncSession

from syncmaster.db.models import Connection, Transfer
from syncmaster.db.models import Connection
from syncmaster.db.repositories.repository_with_owner import RepositoryWithOwner
from syncmaster.db.utils import Pagination
from syncmaster.exceptions import EntityNotFoundError, SyncmasterError
from syncmaster.exceptions.connection import (
ConnectionNotFoundError,
ConnectionOwnerError,
ConnectionTypeUpdateError,
DuplicatedConnectionNameError,
)
from syncmaster.exceptions.group import GroupNotFoundError
Expand Down Expand Up @@ -84,14 +82,9 @@ async def update(
name: str | None,
description: str | None,
data: dict[str, Any],
linked_transfers: Sequence[Transfer],
) -> Connection:
try:
connection = await self.read_by_id(connection_id=connection_id)
if data.get("type", None) is not None:
if data["type"] != connection.data["type"]:
if linked_transfers:
raise ConnectionTypeUpdateError
for key in connection.data:
data[key] = data.get(key, None) or connection.data[key]

Expand Down