Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Bump old deps, fix tests #361

Merged
merged 12 commits into from
Feb 23, 2024
Merged

fix: Bump old deps, fix tests #361

merged 12 commits into from
Feb 23, 2024

Conversation

yammesicka
Copy link
Member

No description provided.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

PR Type: Refactoring

PR Summary: This pull request encompasses a series of refactoring changes aimed at improving code readability, maintainability, and performance. It includes updates to the handling of hashing methods in user models, adjustments to the way solution instances are created, enhancements to rate limiting storage, and clarifications in the notifications system. Additionally, it involves code style improvements in tests and other minor refactoring across various files.

Decision: Comment

📝 Type: 'Refactoring' - not supported yet.
  • Sourcery currently only approves 'Typo fix' PRs.
✅ Issue addressed: this change correctly addresses the issue or implements the desired feature.
No details provided.
📝 Complexity: the changes are too large or complex for Sourcery to approve.
  • Unsupported files: the diff contains files that Sourcery does not currently support during reviews.
  • Big diff: the diff is too large to approve with confidence.

General suggestions:

  • Consider future-proofing the approach to supported hashing methods by using a more dynamic solution, such as a configuration file or database table, to facilitate easier updates.
  • When directly accessing attributes of objects like exercise.id and solver.id, it's beneficial to use methods or properties to enhance encapsulation and maintainability.
  • For rate limiting storage, especially in a production or distributed environment, using in-memory storage might lead to inconsistencies. A centralized storage solution like Redis or a database is recommended.
  • Maintain consistency in parameter types across the codebase to avoid ambiguity, especially when using union types like int | User. Consider using a single type or splitting functions to handle different types more explicitly.
  • When dealing with path-like objects, using os.fspath() for conversion can ensure compatibility across different Python versions and clarify the code's intention.

Thanks for using Sourcery. We offer it for free for open source projects and would be very grateful if you could help us grow. If you like it, would you consider sharing Sourcery on your favourite social media? ✨

Share Sourcery

Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

@@ -247,14 +247,15 @@ def __str__(self):
@pre_save(sender=User)
def on_save_handler(model_class, instance, created):
"""Hash password on creation/save."""
supported_hashing = ('pbkdf2:sha256', 'scrypt:')
Copy link

Choose a reason for hiding this comment

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

suggestion (llm): While the introduction of a tuple to check for supported hashing methods improves readability and maintainability, consider extending this approach to accommodate future hashing methods more dynamically. For instance, maintaining a configuration file or a database table for supported hashing methods could allow for easier updates without modifying the codebase.

@@ -707,8 +706,8 @@ def create_solution(
raise AlreadyExists('This solution already exists.')

instance = cls.create(**{
cls.exercise.name: exercise,
cls.solver.name: solver,
cls.exercise.name: exercise.id,
Copy link

Choose a reason for hiding this comment

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

suggestion (llm): Directly accessing the id attribute of exercise and solver objects for the creation of a solution instance introduces a tight coupling between the create_solution method and the internal structure of these objects. Consider using a method or property of these objects to obtain the necessary identifiers to enhance encapsulation and maintainability.

limiter = Limiter(
app=webapp,
key_func=get_remote_address,
storage_uri='memory://',
Copy link

Choose a reason for hiding this comment

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

issue (llm): Using in-memory storage for rate limiting in a production environment might not be the best choice, especially if the application is expected to run in a distributed setup. This could lead to inconsistencies in rate limiting. Consider using a centralized storage solution like Redis or a database that supports all instances of the application.

@@ -33,7 +33,10 @@ def read(user: Optional[User] = None, id_: Optional[int] = None) -> bool:
return all(is_success) # Not gen to prevent lazy evaluation


def read_related(related_id: int, user: int):
def read_related(related_id: int, user: int | User):
Copy link

Choose a reason for hiding this comment

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

suggestion (llm): The use of union type int | User for the user parameter in read_related function improves flexibility but also introduces ambiguity in the function's interface. It's recommended to maintain consistency in parameter types across the codebase. If the function is expected to work with both User objects and user IDs, consider splitting this into two distinct functions or consistently use one type and perform necessary conversions within the function.

@@ -209,7 +209,7 @@ def _load_files_from_repository(self) -> typing.List[upload.File]:
"""
with tempfile.TemporaryDirectory() as tempdir:
self._execute_command(
args=['git', 'clone', self.repository_folder, '.'],
args=['git', 'clone', str(self.repository_folder), '.'],
Copy link

Choose a reason for hiding this comment

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

suggestion (llm): Explicitly converting self.repository_folder to a string suggests that its type might not be inherently a string. If self.repository_folder is expected to be a path-like object, consider using os.fspath() for conversion to ensure compatibility across different Python versions and clarity in the code's intention.

Copy link

codecov bot commented Feb 23, 2024

Codecov Report

Attention: Patch coverage is 91.71598% with 14 lines in your changes are missing coverage. Please review.

Project coverage is 80.12%. Comparing base (89abbf3) to head (aabb6f4).

Files Patch % Lines
lms/lmsweb/views.py 93.98% 8 Missing ⚠️
lms/lmsdb/models.py 66.66% 2 Missing ⚠️
lms/lmsweb/tools/validators.py 75.00% 2 Missing ⚠️
lms/lmstests/public/unittests/import_tests.py 0.00% 1 Missing ⚠️
lms/lmsweb/git_service.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #361      +/-   ##
==========================================
- Coverage   84.13%   80.12%   -4.01%     
==========================================
  Files          63       63              
  Lines        2949     2953       +4     
==========================================
- Hits         2481     2366     -115     
- Misses        468      587     +119     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yammesicka yammesicka merged commit 4b9c051 into master Feb 23, 2024
2 of 3 checks passed
@yammesicka yammesicka deleted the upgrade-all branch February 23, 2024 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants