Skip to content

Commit

Permalink
fix: BI-6124 init mypy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ForrestGump committed Mar 10, 2025
1 parent 74dd4d6 commit de93e00
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/dl_api_lib/dl_api_lib/app/control_api/resources/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ def _handle_conn_test_exc(exception: Exception) -> NoReturn:
@ns.route("/test_connection_params")
class ConnectionParamsTester(BIResource):
@schematic_request(ns=ns)
def post(self): # type: ignore # TODO: fix
def post(self) -> None:
service_registry = self.get_service_registry()
schema = GenericConnectionSchema(context=self.get_schema_ctx(schema_operations_mode=CreateMode.test))
body_json = dict(request.json) # type: ignore # 2024-01-24 # TODO: Argument 1 to "dict" has incompatible type "Any | None"; expected "SupportsKeysAndGetItem[Any, Any]" [arg-type]
body_json = request.get_json()
assert isinstance(body_json, dict)
body_json["name"] = "mocked_name" # FIXME: BI-4639
try:
conn: ConnectionBase = schema.load(body_json)
Expand All @@ -93,15 +94,16 @@ def post(self): # type: ignore # TODO: fix
@ns.route("/test_connection/<connection_id>")
class ConnectionTester(BIResource):
@schematic_request(ns=ns)
def post(self, connection_id): # type: ignore # TODO: fix
def post(self, connection_id: str) -> None:
usm = self.get_us_manager()
service_registry = self.get_service_registry()
conn = usm.get_by_id(connection_id, expected_type=ConnectionBase)
conn_orig = usm.clone_entry_instance(conn)
assert isinstance(conn_orig, ConnectionBase) # for typing
need_permission_on_entry(conn, USPermissionKind.read)

body_json = dict(request.json) # type: ignore # 2024-01-24 # TODO: Argument 1 to "dict" has incompatible type "Any | None"; expected "SupportsKeysAndGetItem[Any, Any]" [arg-type]
body_json = request.get_json()
assert isinstance(body_json, dict)

has_changes = len(body_json.keys()) > 0
if has_changes:
Expand Down Expand Up @@ -131,7 +133,7 @@ def post(self, connection_id): # type: ignore # TODO: fix
class ConnectionsImportList(BIResource):
@put_to_request_context(endpoint_code="ConnectionImport")
@schematic_request(ns=ns)
def post(self): # type: ignore # TODO: fix
def post(self) -> None:
us_manager = self.get_us_manager()
notifications = []

Expand Down Expand Up @@ -173,7 +175,7 @@ def post(self): # type: ignore # TODO: fix
class ConnectionsList(BIResource):
@put_to_request_context(endpoint_code="ConnectionCreate")
@schematic_request(ns=ns)
def post(self): # type: ignore # TODO: fix
def post(self) -> None:
us_manager = self.get_us_manager()

conn_availability = self.get_service_registry().get_connector_availability()
Expand Down Expand Up @@ -229,10 +231,10 @@ def delete(self, connection_id: str) -> None:

@put_to_request_context(endpoint_code="ConnectionUpdate")
@schematic_request(ns=ns)
def put(self, connection_id): # type: ignore # TODO: fix
def put(self, connection_id: str) -> None:
us_manager = self.get_us_manager()

with us_manager.get_locked_entry_cm(ConnectionBase, connection_id) as conn: # type: ignore # TODO: fix
with us_manager.get_locked_entry_cm(ConnectionBase, connection_id) as conn:
need_permission_on_entry(conn, USPermissionKind.edit)
conn_orig = us_manager.clone_entry_instance(conn)
assert isinstance(conn_orig, ConnectionBase)
Expand All @@ -242,7 +244,9 @@ def put(self, connection_id): # type: ignore # TODO: fix
schema = schema_cls(context=schema_ctx)

try:
changes = schema.load(request.json) # type: ignore # 2024-01-24 # TODO: Argument 1 to "load" of "Schema" has incompatible type "Any | None"; expected "Mapping[str, Any] | Iterable[Mapping[str, Any]]" [arg-type]
body_json = request.get_json()
assert isinstance(body_json, dict)
changes = schema.load(body_json)
schema.update_object(conn, changes)
except MValidationError as e:
return e.messages, 400
Expand Down Expand Up @@ -319,7 +323,7 @@ class ConnectionInfoSources(BIResource):
query=ConnectionSourcesQuerySchema(),
responses={200: ("Success", ConnectionSourceTemplatesResponseSchema())},
)
def get(self, connection_id, query): # type: ignore # TODO: fix
def get(self, connection_id: str, query: dict) -> dict:
connection = self.get_us_manager().get_by_id(connection_id, expected_type=ConnectionBase)

service_registry = self.get_service_registry()
Expand Down Expand Up @@ -357,7 +361,7 @@ class ConnectionInfoSourceSchema(BIResource):
body=ConnectionInfoSourceSchemaQuerySchema(),
responses={200: ("Success", ConnectionInfoSourceSchemaResponseSchema())},
)
def post(self, connection_id: str, body: dict): # type: ignore # TODO: fix
def post(self, connection_id: str, body: dict) -> dict:
connection = self.get_us_manager().get_by_id(connection_id, expected_type=ConnectionBase)
sr = self.get_service_registry()

Expand Down

0 comments on commit de93e00

Please sign in to comment.