mirror of
https://github.com/langgenius/dify.git
synced 2026-09-08 11:04:27 +08:00
style(api): remove unnecessary type conversions in services, repositories and tests (#41856)
This commit is contained in:
parent
a57e04aa49
commit
d138effca8
@ -142,7 +142,7 @@ def handle(sender: Message, **kwargs):
|
||||
"created_by": get_credit_usage_created_by(app_mode),
|
||||
}
|
||||
credit_deduction_context: _CreditDeductionContext = {
|
||||
"request_id": str(message.id) if message.id else None,
|
||||
"request_id": message.id or None,
|
||||
"metadata": credit_deduction_metadata,
|
||||
}
|
||||
agent_gateway_metered = (
|
||||
|
||||
@ -547,7 +547,7 @@ def build_application_services(
|
||||
passwords=passwords,
|
||||
tokens=RedisForgotPasswordTokenGateway(
|
||||
redis=redis,
|
||||
expiry_seconds=int(dify_config.RESET_PASSWORD_TOKEN_EXPIRY_MINUTES * 60),
|
||||
expiry_seconds=dify_config.RESET_PASSWORD_TOKEN_EXPIRY_MINUTES * 60,
|
||||
),
|
||||
codes=SecureForgotPasswordCodeGenerator(),
|
||||
notifications=CeleryForgotPasswordNotificationGateway(),
|
||||
|
||||
@ -44,7 +44,7 @@ class SQLAlchemyOAuthAccessTokenRepository(AccountSessionRepository):
|
||||
.offset(offset)
|
||||
.limit(limit)
|
||||
).all()
|
||||
return int(total), tuple(self._to_snapshot(row) for row in rows)
|
||||
return total, tuple(self._to_snapshot(row) for row in rows)
|
||||
|
||||
@override
|
||||
def revoke(
|
||||
@ -79,7 +79,7 @@ class SQLAlchemyOAuthAccessTokenRepository(AccountSessionRepository):
|
||||
@staticmethod
|
||||
def _to_snapshot(row: OAuthAccessToken) -> AccountSessionSnapshot:
|
||||
return AccountSessionSnapshot(
|
||||
id=str(row.id),
|
||||
id=row.id,
|
||||
prefix=row.prefix,
|
||||
client_id=row.client_id,
|
||||
device_label=row.device_label,
|
||||
|
||||
@ -19,6 +19,6 @@ class WebAppAccessQueryRepository(WebAppAccessQuery):
|
||||
try:
|
||||
with self._session_factory() as session:
|
||||
app_id = session.scalar(select(Site.app_id).where(Site.code == app_code).limit(1))
|
||||
return str(app_id) if app_id is not None else None
|
||||
return app_id if app_id is not None else None
|
||||
except (DBAPIError, TimeoutError) as e:
|
||||
raise WebAppAccessUnavailableError from e
|
||||
|
||||
@ -151,8 +151,8 @@ class RBACWorkspaceMemberAccessSync(WorkspaceMemberAccessSync):
|
||||
from tasks.initialize_created_app_rbac_access_task import sync_joined_workspace_member_rbac_access_task
|
||||
|
||||
sync_joined_workspace_member_rbac_access_task.delay(
|
||||
str(workspace_id),
|
||||
str(account_id),
|
||||
workspace_id,
|
||||
account_id,
|
||||
operator_account_id=None,
|
||||
)
|
||||
|
||||
@ -221,8 +221,8 @@ class TokenManagerChangeEmailTokenGateway(ChangeEmailTokenGateway):
|
||||
return None
|
||||
token_kwargs = {
|
||||
"account_id": token_data.account_id,
|
||||
"email": str(token_data.email),
|
||||
"old_email": str(token_data.old_email),
|
||||
"email": token_data.email,
|
||||
"old_email": token_data.old_email,
|
||||
"code": token_data.code,
|
||||
}
|
||||
if isinstance(token_data, ChangeEmailOldEmailToken):
|
||||
|
||||
@ -447,7 +447,7 @@ class SQLAlchemyConsoleAuthProvisioningGateway(AccountProvisioningGateway, Works
|
||||
).data
|
||||
for role in roles:
|
||||
if role.is_builtin and role.category == "global_system_default" and role.role_tag == "owner":
|
||||
return str(role.id)
|
||||
return role.id
|
||||
raise ValueError(f"Builtin RBAC owner role not found in tenant {tenant_id}")
|
||||
|
||||
|
||||
|
||||
@ -3623,7 +3623,7 @@ class SkillManagementService:
|
||||
except yaml.YAMLError as exc:
|
||||
line = None
|
||||
if isinstance(exc, MarkedYAMLError) and exc.problem_mark is not None:
|
||||
line = int(exc.problem_mark.line) + 2
|
||||
line = exc.problem_mark.line + 2
|
||||
raise SkillManagementServiceError(
|
||||
"invalid_skill_md",
|
||||
f"SKILL.md frontmatter YAML is invalid: {exc}",
|
||||
|
||||
@ -219,12 +219,11 @@ class TestDatasetApiKeyListResource:
|
||||
"""
|
||||
|
||||
def _bound_dataset_ids(self, session: Session, api_token_id: str) -> set[str]:
|
||||
return {
|
||||
str(dataset_id)
|
||||
for dataset_id in session.scalars(
|
||||
return set(
|
||||
session.scalars(
|
||||
select(DatasetApiTokenBinding.dataset_id).where(DatasetApiTokenBinding.api_token_id == api_token_id)
|
||||
).all()
|
||||
}
|
||||
)
|
||||
|
||||
def test_create_unbound_key(
|
||||
self,
|
||||
@ -402,10 +401,9 @@ class TestDatasetDeleteCascadesToScopedKeys:
|
||||
assert resp.status_code == 204
|
||||
# The key survives, still scoped to the remaining dataset only.
|
||||
assert db_session_with_containers.scalar(select(ApiToken).where(ApiToken.id == api_key_id)) is not None
|
||||
remaining = {
|
||||
str(ds_id)
|
||||
for ds_id in db_session_with_containers.scalars(
|
||||
remaining = set(
|
||||
db_session_with_containers.scalars(
|
||||
select(DatasetApiTokenBinding.dataset_id).where(DatasetApiTokenBinding.api_token_id == api_key_id)
|
||||
).all()
|
||||
}
|
||||
)
|
||||
assert remaining == {other_id}
|
||||
|
||||
@ -258,7 +258,7 @@ from controllers.web.remote_files import RemoteFileUploadPayload
|
||||
class TestRemoteFileUploadPayload:
|
||||
def test_valid_url(self) -> None:
|
||||
p = RemoteFileUploadPayload(url="https://example.com/file.pdf")
|
||||
assert str(p.url) == "https://example.com/file.pdf"
|
||||
assert p.url == "https://example.com/file.pdf"
|
||||
|
||||
def test_url_syntax_is_validated_by_remote_file_service(self) -> None:
|
||||
payload = RemoteFileUploadPayload(url="not-a-url")
|
||||
|
||||
@ -319,7 +319,7 @@ class TestResolveAgent:
|
||||
@pytest.fixture(autouse=True)
|
||||
def _publish_visibility(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def is_publish_visible(*, agent: Agent, **_kwargs: object) -> bool:
|
||||
return bool(agent.active_config_is_published)
|
||||
return agent.active_config_is_published
|
||||
|
||||
monkeypatch.setattr(
|
||||
app_generator,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user