Skip to content

more assert - #24996

Merged
crazywoola merged 18 commits into
langgenius:mainfrom
asukaminato0721:more-assert
Sep 8, 2025
Merged

crazywoola merged 18 commits into
langgenius:mainfrom
asukaminato0721:more-assert

Conversation

@asukaminato0721

Copy link
Copy Markdown
Contributor

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

part of #24406

Summary

Screenshots

Before After
... ...

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. 💪 enhancement New feature or request labels Sep 2, 2025
@asukaminato0721

Copy link
Copy Markdown
Contributor Author

why all

>       assert isinstance(current_user, Account) and current_user.timezone is not None
E       AssertionError

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Sep 3, 2025
Comment thread api/services/dataset_service.py Resolved
Comment thread api/services/dataset_service.py Resolved
Copilot AI review requested due to automatic review settings September 5, 2025 12:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds type checking assertions to services that use current_user throughout the Dify codebase. The changes enhance runtime type safety by asserting that current_user is an instance of Account and that required attributes like current_tenant_id and timezone are not None where they are expected to exist.

  • Replaces mock usage patterns in tests with create_autospec(Account, instance=True) for better type safety
  • Adds runtime assertions for current_user being an Account instance and having required non-None attributes
  • Updates import statements to use libs.login.current_user instead of flask_login.current_user

Reviewed Changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.

File Description
test files (*.py) Replace Mock() with create_autospec(Account, instance=True) for current_user mocking
service files (*.py) Add runtime assertions for current_user type and required attributes
controllers/console/billing/billing.py Add type assertions and null-safe string concatenation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Sep 8, 2025
@crazywoola
crazywoola merged commit 16a3e21 into langgenius:main Sep 8, 2025
@asukaminato0721
asukaminato0721 deleted the more-assert branch September 8, 2025 02:32
Ssazurov pushed a commit to Ssazurov/dify that referenced this pull request Aug 8, 2026
Signed-off-by: -LAN- <laipz8200@outlook.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: -LAN- <laipz8200@outlook.com>
Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💪 enhancement New feature or request lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants