Skip to content

Tech officer tools#21

Open
dbca-serkank wants to merge 10 commits intouatfrom
feature/tech-officers
Open

Tech officer tools#21
dbca-serkank wants to merge 10 commits intouatfrom
feature/tech-officers

Conversation

@dbca-serkank
Copy link
Collaborator

No description provided.

Comment on lines +15 to +17
operations = [
migrations.CreateModel(
name='QuestionnairePermission',
Copy link

Choose a reason for hiding this comment

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

Bug: A new migration 0002_* conflicts with an existing migration of the same number, creating a branched history that will cause Django's migrate command to fail.
Severity: CRITICAL

Suggested Fix

Resolve the conflicting migrations. This can be done by re-numbering the new migration (e.g., to 0004_*), updating its dependencies to point to the latest existing migration, and then running python manage.py makemigrations --merge to create a merge migration that resolves the divergent paths.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location:
backend/questionnaires/migrations/0002_questionnairepermission_questionnairemembership_and_more.py#L15-L17

Potential issue: The pull request introduces a new migration
`0002_questionnairepermission_questionnairemembership_and_more.py` which conflicts with
an existing migration `0002_alter_questionnaire_document.py`. Both migrations share the
same number and depend on `0001_initial`, creating a branched migration history.
Django's migration system cannot resolve this conflict automatically and will raise an
`InconsistentMigrationHistory` error during deployment. This will prevent migrations
from running and block the application from starting.

Did we get this right? 👍 / 👎 to inform future reviews.

"user__email",
"user__username",
"questionnaire__name",
"questionnaire__slug",
Copy link

Choose a reason for hiding this comment

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

Bug: The QuestionnaireMembershipAdmin search_fields references questionnaire__slug, but the slug field is removed from the Questionnaire model in a later migration, which will cause a FieldError.
Severity: HIGH

Suggested Fix

Remove the 'questionnaire__slug' entry from the search_fields tuple in the QuestionnaireMembershipAdmin class located in backend/questionnaires/admin.py. Replace it with a valid field from the Questionnaire model if search functionality on a related field is still desired.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: backend/questionnaires/admin.py#L29

Potential issue: The `QuestionnaireMembershipAdmin` class defines `questionnaire__slug`
in its `search_fields`. However, the `slug` field is removed from the `Questionnaire`
model in migration
`0003_remove_questionnaire_qnaire_unique_slug_version_desc_and_more.py`. After
migrations are applied, any attempt to use the search bar in the
`QuestionnaireMembership` admin page will cause Django to query a non-existent field,
raising a `FieldError` and crashing the admin view.

Did we get this right? 👍 / 👎 to inform future reviews.

Comment on lines +81 to +90
class QuestionnairePermission(models.Model):
"""
Declarative permissions for questionnaire membership.

- codename: stable machine-readable identifier (used in code checks)
- name: human-friendly label shown in the Django admin
- description: free text explaining what this permission allows
"""

id = models.BigAutoField(primary_key=True)
Copy link

Choose a reason for hiding this comment

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

Bug: The new models QuestionnairePermission and QuestionnaireMembership are missing corresponding database migrations, which will cause the application to crash on startup.
Severity: CRITICAL

Suggested Fix

Generate the missing migrations by running python manage.py makemigrations questionnaires. Commit the newly created migration file and include it in the pull request.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: backend/questionnaires/models.py#L81-L90

Potential issue: The new models `QuestionnairePermission` and `QuestionnaireMembership`,
along with the `Questionnaire.members` ManyToMany field, have been defined but the
necessary Django database migrations have not been generated. When the application
starts, Django's admin will attempt to register these models, as they are decorated with
`@admin.register`. This will trigger database queries for tables that do not exist,
causing the application to fail on startup with a database error like `OperationalError:
no such table`.

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.

1 participant