-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Conversation
This commit fixes the style issues introduced in a2f0e0e according to the output from Black, isort and Ruff Formatter. Details: None
Merging to
|
Reviewer's Guide by SourceryThe 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 classesclassDiagram
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"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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!
Quality Gate passedIssues Measures |
Here's the code health analysis summary for commits Analysis Summary
|
) | ||
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, |
There was a problem hiding this comment.
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." |
There was a problem hiding this comment.
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.
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." |
There was a problem hiding this comment.
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." | ||
) | ||
|
There was a problem hiding this comment.
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.
("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)), |
There was a problem hiding this comment.
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.
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, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
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: