Skip to content

Conversation

@jortel
Copy link
Contributor

@jortel jortel commented Aug 26, 2025

The resolvers expect the Application.Assessments[].Sections to be populated.
This works for Get() because it uses db.Fetch() with clause.Associations which fetches the entire nested Assessment object. List() uses a a custom join for performance and memory footprint.

This is a regression introduced by #789 RE: application list performance and memory footprint. OPTIMIZATION.

closes #891

@coderabbitai
Copy link

coderabbitai bot commented Aug 26, 2025

Walkthrough

Adds a local byte-slice field to hold JSON-serialized assessment sections in the List query result, selects at.Sections into it, and unmarshals into model.Assessment.Sections when an AssessmentId exists. Errors from unmarshalling are ignored. No exported API changes.

Changes

Cohort / File(s) Summary
Application list data model and query
api/application.go
Add M.AssessmentSections []byte; extend SELECT to include at.Sections AS AssessmentSections; on List build, unmarshal AssessmentSections into Assessment.Sections when AssessmentId present; ignore JSON unmarshal error; adjust local projection ordering.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client
  participant API as Application List (API)
  participant DB as Database

  Client->>API: List applications
  API->>DB: SELECT ..., at.Sections AS AssessmentSections, ...
  DB-->>API: Rows with AssessmentId, QuestionnaireId, AssessmentSections
  rect rgba(220,245,255,0.5)
    note over API: Build response
    API->>API: If AssessmentId != nil<br/>json.Unmarshal(AssessmentSections) -> Assessment.Sections<br/>(ignore error)
  end
  API-->>Client: Application list (includes Assessment with Sections if present)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Fix incorrect assessment risk shown for assessed applications [#891] Only loads Assessment.Sections into model; no direct change to risk computation/derivation is visible. Unmarshal errors are ignored, making impact uncertain.

Poem

I nibbled bytes and parsed the scenes,
From tables fetched the hidden means;
A JSON burrow, Sections found,
Now hop they do to higher ground.
If risk was lost, may this assist—
A carrot trail no longer missed. 🥕🐇

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

PlatformName string
ReviewId uint
AssessmentId uint
AssessmentSections []byte
Copy link
Contributor Author

Choose a reason for hiding this comment

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

hint: just AssessmentSections added.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
api/application.go (4)

205-206: Good call: carry Sections through the List projection.

Adding AssessmentSections to the M projection is the right minimal data to enable risk/confidence resolution in List without heavy preloads. Consider using json.RawMessage for slightly better intent signaling (alias of []byte) but not required.

-        AssessmentSections []byte
+        AssessmentSections json.RawMessage

228-228: Selecting at.Sections into an alias is correct; consider null-proofing at the SQL layer (optional).

If at.Sections can be NULL, Unmarshal(nil, ...) returns "unexpected end of JSON input". You’re guarding by requiring AssessmentId > 0, but Sections might still be NULL. Optionally COALESCE to an empty array/object to avoid nils (PostgreSQL example shown).

-        "at.Sections        AssessmentSections",
+        "COALESCE(at.Sections, '[]'::jsonb) AssessmentSections",

If DB portability matters, keep as-is and guard before unmarshalling (see next comment).


299-305: Don’t discard JSON errors; guard and fail soft.

Swallowing Unmarshal errors can silently regress back to "Unknown" risk. Guard for empty/nil payloads and, if decode fails, skip populating Sections but keep the request alive. This improves debuggability without breaking List responses.

-                _ = json.Unmarshal(m.AssessmentSections, &ref.Sections)
+                if len(m.AssessmentSections) > 0 {
+                    if err := json.Unmarshal(m.AssessmentSections, &ref.Sections); err != nil {
+                        // soft-fail: keep Sections empty so resolver degrades gracefully.
+                        // Optional: add debug logging if a logger is available.
+                    }
+                }

If the codebase prefers the migration/json shim for consistency:

-                if len(m.AssessmentSections) > 0 {
-                    if err := json.Unmarshal(m.AssessmentSections, &ref.Sections); err != nil {
+                if len(m.AssessmentSections) > 0 {
+                    if err := jsonpkg.Unmarshal(m.AssessmentSections, &ref.Sections); err != nil {

…and add at the top:

-    "encoding/json"
+    "encoding/json"
+    jsonpkg "github.com/konveyor/tackle2-hub/migration/json"

171-177: Sanity check: this should address #891 end-to-end. Please verify UI paths.

With Sections now loaded in List, Application.WithResolver should compute Assessed/Risk/Confidence correctly for listings and the drawer. Please re-run the repro steps from issue #891 and confirm:

  • Applications list shows correct Risk/Confidence
  • Application drawer shows the same values
  • Reports tab remains consistent

I can help add a focused API test to assert that GET /applications includes non-"Unknown" risk after creating an assessment via POST /applications/{id}/assessments. Want me to draft that?

Also applies to: 333-346

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 1f7e231 and 05b5f96.

📒 Files selected for processing (1)
  • api/application.go (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
api/application.go (1)
migration/json/pkg.go (1)
  • Unmarshal (5-5)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test-unit
  • GitHub Check: build

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.

[BUG] Assessed application do not show the correct assessment risk

2 participants