Skip to content

feat: Create section model#721

Open
swapnil-turing wants to merge 5 commits into
mainfrom
feat/section-9
Open

feat: Create section model#721
swapnil-turing wants to merge 5 commits into
mainfrom
feat/section-9

Conversation

@swapnil-turing
Copy link
Copy Markdown
Collaborator

No description provided.

@augmentcode
Copy link
Copy Markdown

augmentcode Bot commented May 27, 2026

🤖 Augment PR Summary

Summary: Adds a new SQLAlchemy Section model to persist form sections with a per-form-cycle display_order.

Changes: Re-exports Section from app.models so other backend modules can import it directly.

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

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

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread qualia/backend/app/models/section.py Outdated

class Section(Base):
__tablename__ = "section"
__table_args__ = (UniqueConstraint("display_order", name="uq_section_display_order"),)
Copy link
Copy Markdown

@augmentcode augmentcode Bot May 27, 2026

Choose a reason for hiding this comment

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

UniqueConstraint("display_order") combined with a constant default for display_order means inserting multiple Section rows without explicitly setting display_order will quickly hit a uniqueness violation. If ordering is meant to be per form cycle, this global uniqueness constraint also blocks valid duplicates across different cycles.

Severity: high

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

value:useful; category:bug; feedback:Marked useful because this comment caught an ordering constraint that would fail on normal section creation. It showed that two sections with default order or same order in different form cycles could hit a database uniqueness error.

Comment thread qualia/backend/app/models/section.py Outdated
Uuid, ForeignKey("form_cycle.id"), index=True, nullable=True
)
title: Mapped[str | None] = mapped_column(String(255), nullable=True)
display_order: Mapped[int] = mapped_column(Integer, default=0, server_default=text("1"))
Copy link
Copy Markdown

@augmentcode augmentcode Bot May 27, 2026

Choose a reason for hiding this comment

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

display_order has default=0 but server_default=text("1"), which can lead to inconsistent persisted values depending on whether the ORM sends a value vs letting the DB fill it. This kind of mismatch is easy to miss and can break assumptions in ordering logic/tests.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

value:useful; category:bug; feedback:This was useful because it found a default mismatch in a field used for section ordering. It pointed out that ORM inserts and database-default inserts could persist different order values, making list order behavior inconsistent.

Comment thread qualia/backend/app/models/section.py Outdated
)
title: Mapped[str | None] = mapped_column(String(255), nullable=True)
display_order: Mapped[int] = mapped_column(Integer, default=0, server_default=text("1"))
form_cycle: Mapped["FormCycle"] = relationship("FormCycle", back_populates="section")
Copy link
Copy Markdown

@augmentcode augmentcode Bot May 27, 2026

Choose a reason for hiding this comment

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

This relationship("FormCycle", ...) (and the FK to form_cycle.id) requires a FormCycle mapper/table to exist in the same SQLAlchemy Base.metadata; in the current codebase there doesn’t appear to be a FormCycle model, so metadata/table creation or mapper configuration is likely to error when the models are loaded/used.

Severity: high

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

value:useful; category:bug; feedback:Marked useful because this comment caught that the branch referenced a mapper and foreign table not present on this PR base. It meant loading SQLAlchemy metadata or configuring mappers could fail before the section model is usable.

@swapnil-turing
Copy link
Copy Markdown
Collaborator Author

augment review

Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

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

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread qualia/backend/app/models/section.py Outdated
id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, default=uuid.uuid4)
form_cycle_id: Mapped[uuid.UUID] = mapped_column(Uuid, index=True, nullable=False)
title: Mapped[str | None] = mapped_column(String(255), nullable=True)
display_order: Mapped[int] = mapped_column(Integer, default=1, server_default=text("1"))
Copy link
Copy Markdown

@augmentcode augmentcode Bot May 27, 2026

Choose a reason for hiding this comment

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

display_order is currently nullable (no nullable=False), which allows NULL values; this can bypass ordering assumptions and also undermine the uniqueness constraint (since multiple NULLs are typically allowed).

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

value:useful; category:bug; feedback:Marked useful because this comment caught a nullable ordering field that can break section ordering. It pointed out that NULL display orders can bypass uniqueness and make section lists sort unpredictably.

)

id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, default=uuid.uuid4)
form_cycle_id: Mapped[uuid.UUID] = mapped_column(Uuid, index=True, nullable=False)
Copy link
Copy Markdown

@augmentcode augmentcode Bot May 27, 2026

Choose a reason for hiding this comment

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

form_cycle_id looks like it references another table, but there’s no DB-level foreign key constraint here; that can allow orphan Section rows and makes integrity dependent on application code.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

value:valid-but-wont-fix; category:bug; feedback:Marked valid-but-wont-fix because the integrity concern is correct, but this PR base does not include the referenced form cycle table yet. Adding that foreign key now would make metadata creation depend on a table outside this slice and can break model loading.

@swapnil-turing
Copy link
Copy Markdown
Collaborator Author

augment review

Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

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

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

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