-
Notifications
You must be signed in to change notification settings - Fork 0
Psharma/django 5.0 tests fix #44
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
Psharma/django 5.0 tests fix #44
Conversation
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.
Pull Request Overview
This PR adds database feature checks and modifies test models to support SingleStore database compatibility. The changes ensure tests requiring database defaults (db_default) and other specific features only run when supported by the database backend.
- Added
@skipUnlessDBFeature("supports_db_default")decorators to tests usingdb_defaultfunctionality - Modified test models to use explicit through tables for ManyToMany relationships and added SingleStore-specific
ModelStorageManager - Simplified field default models to use static values instead of database function expressions
- Adjusted test expectations for query counts and serialized output
- Fixed test field references in
test_prepare_join_on_clause
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/validation/test_unique.py | Added feature check for supports_db_default to test_unique_db_default test |
| tests/schema/tests.py | Added feature checks for supports_db_default to multiple database default tests |
| tests/model_inheritance/models.py | Added ModelStorageManager to multiple inheritance models for SingleStore compatibility |
| tests/model_formsets/test_uuid.py | Added explicit save operations for parent and formset |
| tests/migrations/test_operations.py | Added feature checks and corrected decorator from supports_expression_defaults to supports_db_default |
| tests/force_insert_update/models.py | Added import and ModelStorageManager for inheritance models |
| tests/fixtures/tests.py | Updated expected query count and removed permissions field from serialized output |
| tests/field_defaults/tests.py | Added debug output and changed test assertions to use static values instead of dynamic functions |
| tests/field_defaults/models.py | Simplified DBDefaultsFunction model to use static values instead of database functions |
| tests/constraints/tests.py | Added feature check for supports_db_default to constraint test |
| tests/basic/tests.py | Added feature check for supports_db_default to primary key test |
| tests/backends/models.py | Added explicit through table for SchoolBus ManyToMany relationship |
| tests/backends/base/test_operations.py | Changed test to use author_name_field instead of author_id_field |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/field_defaults/tests.py
Outdated
| print("\n=== DEBUGGING SQL GENERATION ===") | ||
| schema_editor = connection.schema_editor() | ||
|
|
||
| # Check how defaults are generated | ||
| for field in DBArticle._meta.fields: | ||
| if hasattr(field, 'db_default') and field.db_default is not None: | ||
| try: | ||
| default_sql, params = schema_editor.db_default_sql(field) | ||
| print(f"Field '{field.name}' default SQL: {default_sql}") | ||
| except Exception as e: | ||
| print(f"Field '{field.name}' error: {e}") | ||
|
|
||
| # Check actual table structure | ||
| with connection.cursor() as cursor: | ||
| cursor.execute("DESCRIBE field_defaults_dbarticle") | ||
| columns = cursor.fetchall() | ||
| print("\nActual table columns:") | ||
| for col in columns: | ||
| print(f" {col}") | ||
|
|
||
| # Now run the actual test | ||
| a = DBArticle() | ||
| a.save() | ||
| a.refresh_from_db() | ||
|
|
||
| print(f"\nActual values after refresh:") | ||
| print(f" headline: {a.headline}") | ||
| print(f" pub_date: {a.pub_date}") | ||
| print(f" cost: {a.cost}") |
Copilot
AI
Oct 30, 2025
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.
Debug print statements should be removed from production test code. These debugging statements appear to have been accidentally left in the test after troubleshooting.
tests/field_defaults/tests.py
Outdated
| # === DEBUGGING SQL GENERATION === | ||
| # Field 'id' error: type object 'NOT_PROVIDED' has no attribute 'as_sql' | ||
| # Field 'headline' default SQL: 'Default headline' | ||
| # Field 'pub_date' default SQL: (CURRENT_TIMESTAMP(6)) | ||
| # Field 'cost' default SQL: 3.33 | ||
|
|
||
| # Actual table columns: | ||
| # ('id', 'bigint(20)', 'NO', 'PRI', None, 'auto_increment') | ||
| # ('headline', 'varchar(100)', 'NO', '', 'Default headline', '') | ||
| # ('pub_date', 'datetime(6)', 'NO', '', 'Now()', '') | ||
| # ('cost', 'decimal(3,2)', 'NO', '', '3.33', '') | ||
|
|
||
| # Actual values after refresh: | ||
| # headline: Default headline | ||
| # pub_date: None | ||
| # cost: 3.33 | ||
|
|
Copilot
AI
Oct 30, 2025
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.
Commented-out debug output should be removed from production test code. This appears to be leftover debugging information that should not be committed.
| # === DEBUGGING SQL GENERATION === | |
| # Field 'id' error: type object 'NOT_PROVIDED' has no attribute 'as_sql' | |
| # Field 'headline' default SQL: 'Default headline' | |
| # Field 'pub_date' default SQL: (CURRENT_TIMESTAMP(6)) | |
| # Field 'cost' default SQL: 3.33 | |
| # Actual table columns: | |
| # ('id', 'bigint(20)', 'NO', 'PRI', None, 'auto_increment') | |
| # ('headline', 'varchar(100)', 'NO', '', 'Default headline', '') | |
| # ('pub_date', 'datetime(6)', 'NO', '', 'Now()', '') | |
| # ('cost', 'decimal(3,2)', 'NO', '', '3.33', '') | |
| # Actual values after refresh: | |
| # headline: Default headline | |
| # pub_date: None | |
| # cost: 3.33 |
tests/model_formsets/test_uuid.py
Outdated
| } | ||
| ) | ||
| self.assertIs(formset.is_valid(), True) | ||
|
|
Copilot
AI
Oct 30, 2025
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.
Trailing whitespace should be removed for code cleanliness.
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.
@psharma-1909 please apply suggestion
tests/model_formsets/test_uuid.py
Outdated
|
|
||
| # Save parent first | ||
| formset.instance.save() | ||
|
|
Copilot
AI
Oct 30, 2025
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.
Trailing whitespace should be removed for code cleanliness.
tests/model_formsets/test_uuid.py
Outdated
|
|
||
| # Then save the formset | ||
| formset.save() | ||
|
|
Copilot
AI
Oct 30, 2025
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.
Trailing whitespace should be removed for code cleanliness.
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.
Pull Request Overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/field_defaults/tests.py
Outdated
| def test_field_db_defaults_refresh(self): | ||
|
|
Copilot
AI
Oct 31, 2025
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 function definition line 53 has trailing whitespace, and line 54 is an empty line with extra whitespace. Remove trailing spaces.
| def test_field_db_defaults_refresh(self): | |
| def test_field_db_defaults_refresh(self): |
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.
@psharma-1909 please apply suggestion
tests/field_defaults/tests.py
Outdated
| a = DBArticle() | ||
| a.save() | ||
| a.refresh_from_db() | ||
|
|
Copilot
AI
Oct 31, 2025
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.
Line 58 has trailing whitespace after the blank line. Remove trailing spaces.
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.
@psharma-1909 please apply suggestion
tests/field_defaults/tests.py
Outdated
| a = DBArticle() | ||
| a.save() | ||
| a.refresh_from_db() | ||
|
|
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.
@psharma-1909 please apply suggestion
tests/model_formsets/test_uuid.py
Outdated
| } | ||
| ) | ||
| self.assertIs(formset.is_valid(), 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.
@psharma-1909 please apply suggestion
No description provided.