Skip to content

fix: should set default model type if type not present, close #1752#1760

Merged
looplj merged 1 commit into
unstablefrom
dev-tmp
Jun 2, 2026
Merged

fix: should set default model type if type not present, close #1752#1760
looplj merged 1 commit into
unstablefrom
dev-tmp

Conversation

@looplj

@looplj looplj commented Jun 1, 2026

Copy link
Copy Markdown
Owner

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@greptile-apps

greptile-apps Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a nil-pointer panic in CreateModel and BulkCreateModels that occurred when input.Type was nil — the old code dereferenced the pointer unconditionally with SetType(*input.Type). The fix delegates field application to the ent-generated SetInput/Mutate path, which guards the Type field with a nil check and lets the schema-level Default("chat") supply the value when none is provided.

  • model.go: Both create paths now use SetInput instead of individual Set* calls. The Remark field guard that follows is now redundant (already applied inside Mutate) and can be removed in both functions.
  • model_validation_test.go: Two new integration tests assert the default-type behaviour for single and bulk creation; existing test fixtures are patched to include the required Icon, ModelCard, and Settings fields.

Confidence Score: 4/5

Safe to merge; the core logic change is correct and the new tests exercise the fixed path end-to-end.

The fix correctly removes an unconditional nil-pointer dereference on input.Type and relies on the well-established ent schema default. The only remaining issue is that the explicit Remark guard block is now dead code in both CreateModel and BulkCreateModels, since SetInput already applies Remark through Mutate — but this is harmless at runtime.

The redundant Remark handling in internal/server/biz/model.go (two places) is worth a quick cleanup pass.

Important Files Changed

Filename Overview
internal/server/biz/model.go Replaces explicit field-by-field setters with SetInput in both CreateModel and BulkCreateModels; the generated Mutate method properly handles a nil Type pointer and relies on the schema-level Default("chat"). Minor: the explicit Remark block that follows SetInput is now redundant since Mutate already handles that field.
internal/server/biz/model_validation_test.go Adds two new tests verifying nil-type defaulting behaviour for single and bulk creation, and fills in missing required fields (Icon, ModelCard, Settings) in existing test fixtures.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[CreateModel / BulkCreateModels] --> B{input.Type == nil?}
    B -- "Before fix" --> C["SetType(*input.Type) panic"]
    B -- "After fix" --> D["SetInput calls Mutate"]
    D --> E{Type != nil?}
    E -- yes --> F[m.SetType v]
    E -- no --> G[skip SetType]
    G --> H[ent schema Default 'chat' applied]
    F --> I[Save to DB]
    H --> I
Loading

Comments Outside Diff (2)

  1. internal/server/biz/model.go, line 326-331 (link)

    P2 The Remark field is already handled inside CreateModelInput.Mutate (called by SetInput): if Remark != nil it calls m.SetRemark(*v). The explicit block below duplicates that call, setting the field twice. It's functionally harmless today, but if the generated Mutate logic ever changes (e.g. adds a SetNillableRemark path), this manual override could silently diverge.

  2. internal/server/biz/model.go, line 384-389 (link)

    P2 Same redundancy as in CreateModel: SetInput(*input) already applies Remark via Mutate. The explicit guard below is a leftover from the pre-refactor style and can be dropped to keep the two create paths consistent.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Reviews (1): Last reviewed commit: "fix: should set default model type if ty..." | Re-trigger Greptile

@looplj looplj merged commit 8066aa4 into unstable Jun 2, 2026
5 checks passed
junjiangao pushed a commit to junjiangao/axonhub that referenced this pull request Jun 5, 2026
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