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

style: format code with Black, isort and Ruff Formatter #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

deepsource-autofix[bot]
Copy link

@deepsource-autofix deepsource-autofix bot commented Dec 20, 2024

This commit fixes the style issues introduced in a2f0e0e according to the output
from Black, isort and Ruff Formatter.

Details: None

Summary by Sourcery

Enhancements:

  • Reformat code using Black, isort, and Ruff Formatter for consistent code style across the project.

This commit fixes the style issues introduced in a2f0e0e according to the output
from Black, isort and Ruff Formatter.

Details: None
Copy link

trunk-io bot commented Dec 20, 2024

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

Copy link

sourcery-ai bot commented Dec 20, 2024

Reviewer's Guide by Sourcery

The pull request applies code formatting changes across multiple files using Black, isort, and Ruff Formatter. These changes include reformatting strings, adjusting line breaks, and sorting imports to improve code readability and maintainability.

Class diagram for error schema classes

classDiagram
    class ErrorSchema {
      +str code
      +str message
      +str user_friendly_message
    }
    class ResourceNotFound404Schema {
      +str code = 'ResourceNotFound'
      +str message
      +str user_friendly_message
    }
    class Conflict409Schema {
      +str code = 'Conflict'
      +str message
    }
    class ServiceUnavailable503Schema {
      +str code = 'ServiceUnavailable'
      +str message
      +str user_friendly_message
    }
    ErrorSchema <|-- ResourceNotFound404Schema
    ErrorSchema <|-- Conflict409Schema
    ErrorSchema <|-- ServiceUnavailable503Schema
    note for ResourceNotFound404Schema "Long messages reformatted"
    note for Conflict409Schema "Long message reformatted"
    note for ServiceUnavailable503Schema "Long message reformatted"
Loading

File-Level Changes

Change Details Files
Code formatting using Black, isort, and Ruff Formatter.
  • Reformatted code to adhere to Black's style guide, including changes in string quoting and line breaks.
  • Sorted imports according to isort's rules.
  • Applied Ruff Formatter for additional style corrections.
tests/test_django/app/migrations/0001_initial.py
django_ninja_crudl/errors/schemas.py
tests/test_django/wsgi.py
django_ninja_crudl/crudl.py
tests/test_django/app/models.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

coderabbitai bot commented Dec 20, 2024

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

We have skipped reviewing this pull request. It seems to have been created by a bot (hey, deepsource-autofix[bot]!). We assume it knows what it's doing!

Copy link
Contributor

deepsource-io bot commented Dec 20, 2024

Here's the code health analysis summary for commits a2f0e0e..8bf7d01. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource Python LogoPython❌ Failure
❗ 4 occurences introduced
🎯 16 occurences resolved
View Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

Comment on lines 32 to 37
)
from pydantic import BaseModel

from django2pydantic import Infer, ModelFields
from django2pydantic.schema import Schema
from django_ninja_crudl.base import CrudlBaseMixin
from django_ninja_crudl.errors.openapi_extras import (
not_authorized_openapi_extra,

Choose a reason for hiding this comment

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

Consider improving the naming of not_authorized_openapi_extra and throttle_openapi_extra to more descriptive names that convey their purpose more clearly. For example, openapi_extra_unauthorized_response and openapi_extra_throttle_response might provide immediate context about their usage in OpenAPI documentation enhancements.

@@ -126,7 +126,6 @@

model_class: type[Model] = meta.model_class


api_meta = getattr(model_class, "CrudlApiMeta", meta)
if api_meta is None:
msg = f"CrudlApiMeta is required for model '{name}' or in the model itself."

Choose a reason for hiding this comment

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

The error message for a missing CrudlApiMeta is not very descriptive. Consider enhancing the message to explain what CrudlApiMeta should contain or why it is essential. For example: CrudlApiMeta is required for model '{name}' or in the model itself to define necessary API metadata such as fields and permissions. This would help developers understand the error context better and resolve it more efficiently.

Comment on lines +41 to +45
message: str = (
"The requested resource was not found or you do not have permission to access it."
)
user_friendly_message: str = (
"The requested resource was not found or you do not have permission to access it."

Choose a reason for hiding this comment

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

The message and user_friendly_message in ResourceNotFound404Schema are identical, which introduces redundancy. This could be simplified to improve maintainability and reduce potential confusion.

Recommended Solution:
Consider using a single message attribute or ensure that the user_friendly_message provides a simplified or different perspective that is more accessible to end-users.

message: str = "The request could not be completed due to a conflict with the current state of the resource."
message: str = (
"The request could not be completed due to a conflict with the current state of the resource."
)

Choose a reason for hiding this comment

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

The Conflict409Schema class lacks a user_friendly_message, which is essential for providing a better user experience by explaining the error in a non-technical manner.

Recommended Solution:
Add a user_friendly_message that simplifies the technical message to help end-users understand the nature of the conflict without needing deep technical knowledge.

Comment on lines +77 to +103
("isbn", models.CharField(max_length=13, unique=True)),
("publication_date", models.DateField()),
("authors", models.ManyToManyField(to="app.author")),
(
"publisher",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="app.publisher"
),
),
],
options={
'default_related_name': 'books',
"default_related_name": "books",
},
),
migrations.CreateModel(
name='BookCopy',
name="BookCopy",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('inventory_number', models.CharField(max_length=20, unique=True)),
('book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.book')),
('library', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.library')),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("inventory_number", models.CharField(max_length=20, unique=True)),

Choose a reason for hiding this comment

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

Unique Constraints on Fields

The fields isbn in the Book model and inventory_number in the BookCopy model are marked as unique. While this is generally a good practice for data integrity, it can lead to performance issues if these fields are frequently queried but not properly indexed. Consider adding explicit database indexes to these fields to improve query performance.

Recommendation:
Add indexes using models.Index(fields=['isbn'], name='idx_isbn') for the Book model and models.Index(fields=['inventory_number'], name='idx_inventory_number') for the BookCopy model to ensure efficient lookups.

Comment on lines +83 to +144
on_delete=django.db.models.deletion.CASCADE, to="app.publisher"
),
),
],
options={
'default_related_name': 'books',
"default_related_name": "books",
},
),
migrations.CreateModel(
name='BookCopy',
name="BookCopy",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('inventory_number', models.CharField(max_length=20, unique=True)),
('book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.book')),
('library', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.library')),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("inventory_number", models.CharField(max_length=20, unique=True)),
(
"book",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="app.book"
),
),
(
"library",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="app.library"
),
),
],
options={
'default_related_name': 'book_copies',
"default_related_name": "book_copies",
},
),
migrations.CreateModel(
name='Borrowing',
name="Borrowing",
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('borrow_date', models.DateField()),
('return_date', models.DateField(blank=True, null=True)),
('book_copy', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.bookcopy')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("borrow_date", models.DateField()),
("return_date", models.DateField(blank=True, null=True)),
(
"book_copy",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="app.bookcopy"
),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,

Choose a reason for hiding this comment

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

Cascade Delete in Foreign Key Relationships

The foreign key relationships in the Book, BookCopy, Borrowing models use CASCADE as the deletion rule. This means that deleting a record in the parent table (Publisher, Book, Library, BookCopy, User) will automatically delete all associated records in the child model. This can lead to unintentional data loss if not handled carefully.

Recommendation:
Review the business logic to ensure that cascade deletion is intended. If not, consider changing the deletion rule to PROTECT or SET_NULL to prevent accidental data deletions.

@@ -2,10 +2,10 @@

from typing import ClassVar, override

Choose a reason for hiding this comment

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

The import from typing import ClassVar, override seems to incorrectly include override, which is not part of the Python typing module. This might be a typo or a misunderstanding of the module's capabilities. If override is intended to be used as a decorator for method overriding, ensure it is imported from the correct library or framework that provides this functionality, or remove it if it's not applicable.

@@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_django.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_django.settings")

Choose a reason for hiding this comment

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

Hardcoding the DJANGO_SETTINGS_MODULE in the WSGI file can lead to configuration errors when deploying to different environments (development, testing, production). It's recommended to manage this setting through environment variables set outside the application codebase, ensuring better security and maintainability.

Suggested Change:
Use environment variables to set DJANGO_SETTINGS_MODULE dynamically based on the deployment environment. This can be achieved by using a tool like dotenv or similar to load environment-specific configurations.

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.

0 participants