Skip to content

fix: remove default value for enabled field - #2901

Closed
feitianbubu wants to merge 5192 commits into
QuantumNous:mainfrom
feitianbubu:pr/1cb47ac594d47904af9ceedfe742bc9902c7438b
Closed

fix: remove default value for enabled field#2901
feitianbubu wants to merge 5192 commits into
QuantumNous:mainfrom
feitianbubu:pr/1cb47ac594d47904af9ceedfe742bc9902c7438b

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Feb 9, 2026

Copy link
Copy Markdown
Member

避免mysql下每次重启autoMigrate都会重复执行
ALTER TABLE custom_oauth_providersMODIFY COLUMNenabled boolean default false

Summary by CodeRabbit

  • Chores
    • Updated OAuth provider configuration to modify default value handling for the enabled state.

CaIon and others added 30 commits January 5, 2026 18:55
问题描述:
- 使用 auto 分组的令牌调用 /v1/videos 等 Task 接口时,虽然任务能成功创建,
  但使用日志不显示记录,且不会扣费

根本原因:
- Distribute 中间件在选择渠道后,会将实际选中的分组存储在 ContextKeyAutoGroup 中
- 但 RelayTaskSubmit 函数没有从 context 中读取这个值来更新 info.UsingGroup
- 导致 info.UsingGroup 始终是 "auto" 而不是实际选中的分组(如 "sora2逆")
- 当 auto 分组的倍率配置为 0 时,quota 计算结果为 0
- 日志记录条件 "if quota != 0" 不满足,导致日志不记录、不扣费

修复方案:
- 在 RelayTaskSubmit 函数中计算分组倍率之前,添加从 ContextKeyAutoGroup
  获取实际分组的逻辑
- 使用安全的类型断言,避免潜在的 panic 风险

影响范围:
- 仅影响 Task Relay 流程(/v1/videos, /suno, /kling 等接口)
- 不影响使用具体分组令牌的调用
- 不影响其他 Relay 类型(chat/completions 等已有类似处理逻辑)
…task-logging

fix(task): 修复使用 auto 分组时 Task Relay 不记录日志和不扣费的问题
fix: 设置默认max req body 为128MB
Use the native Gemini Models API (/v1beta/models) instead of the OpenAI-compatible
path when listing models for Gemini channels, improving compatibility with
third-party Gemini-format providers that don't implement OpenAI routes.

- Add paginated model listing with timeout and optional proxy support
- Select an enabled key for multi-key Gemini channels
…etchModels

fix: remove Minimax from FETCHABLE channels
…tchModels

fix(gemini): fetch model list via native v1beta/models endpoint
* feat: /v1/chat/completion -> /v1/response
…-auto-disable

feat: status code auto-disable configuration
* fix: setting ui

* fix: rm global.chat_completions_to_responses_policy

* fix: rm global.chat_completions_to_responses_policy
…Names

fix: clean propertyNames for gemini function
…t-param-override

feat: channel testing supports parameter overriding
* feat: codex channel

* feat: codex channel

* feat: codex oauth flow

* feat: codex refresh cred

* feat: codex usage

* fix: codex err message detail

* fix: codex setting ui

* feat: codex refresh cred task

* fix: import err

* fix: codex store must be false

* fix: chat -> responses tool call

* fix: chat -> responses tool call
Thomas and others added 26 commits February 7, 2026 18:17
…tumNous#2881)

当上游为 AWS Bedrock 时,message_delta 的 usage 可能缺少 input_tokens、
cache_creation_input_tokens、cache_read_input_tokens 等字段,导致与原生
Anthropic 格式不一致。从 message_start 积累的 claudeInfo 中补全这些字段后
重新序列化,确保客户端收到一致的 usage 格式。
Modified the formatUserLogs function to include a startIdx parameter, allowing for more flexible log ID assignment. Updated calls to this function in GetLogByTokenId and GetUserLogs to pass the appropriate starting index.
feat: add Codex channel disclaimer (i18n, OpenAI terms)
feat: Force beta=true parameter for Anthropic channel
feat(oauth): implement custom OAuth provider
fix: Claude stream block index/type transitions
fix: add paragraph breaks between reasoning summary chunks
# Conflicts:
#	service/openaicompat/chat_to_responses.go
…t-stream

feat: channel test with stream=true
…fo-input-token

fix: 使用openai兼容接口调用部分渠道在最终端点为claude原生端点下还是走了openai扣减input_token的逻辑
fix: 补全 streaming message_delta 事件缺失的 input_tokens 和 cache 相关字段
…sponses

feat: /v1/messages -> /v1/responses
…ion-configurable

feat: make 5m cache-creation ratio configurable
fix: 如果模型管理有自定义配置则不合并默认配置
fix: 修复模型管理"参与官方同步"与"状态"开关无法保存的问题
…inity-tips

optimize: channel affinity tips
@coderabbitai

ghost commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

The Enabled boolean field in the CustomOAuthProvider struct has its GORM default tag annotation removed while preserving the JSON serialization tag, affecting field declaration metadata.

Changes

Cohort / File(s) Summary
GORM Tag Removal
model/custom_oauth_provider.go
Removed gorm:"default:false" tag from the Enabled field, keeping the json:"enabled" tag intact.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

Suggested reviewers

  • seefs001

Poem

🐰 A tag once bound, now set free,
The gorm default no longer to be,
One field cleaned, one change so neat,
The CustomOAuth provider's refactor complete! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes the main change: removing the default value from the enabled field in the CustomOAuthProvider struct.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • 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

Comment @coderabbitai help to get the list of available commands and usage tips.

ghost 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.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@model/custom_oauth_provider.go`:
- Line 14: The Enabled field in the CustomOAuthProvider struct is currently
nullable; update its GORM/DB struct tag to include a NOT NULL constraint so the
database enforces non-null booleans (i.e., change the tags on the Enabled field
in model/custom_oauth_provider.go to add `not null`), and ensure any migration
or schema generation will pick up the change so the column is created/altered
with NOT NULL to prevent NULL values.

Id int `json:"id" gorm:"primaryKey"`
Name string `json:"name" gorm:"type:varchar(64);not null"` // Display name, e.g., "GitHub Enterprise"
Slug string `json:"slug" gorm:"type:varchar(64);uniqueIndex;not null"` // URL identifier, e.g., "github-enterprise"
Enabled bool `json:"enabled"` // Whether this provider is enabled

ghost Feb 9, 2026

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.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

cat go.mod | grep -i gorm | head -5

Repository: QuantumNous/new-api

Length of output: 145


🏁 Script executed:

cat -n model/custom_oauth_provider.go

Repository: QuantumNous/new-api

Length of output: 7521


🏁 Script executed:

echo "=== Checking how CustomOAuthProvider is created ===" && \
rg -n --type=go 'CustomOAuthProvider\s*\{' -A 5 | head -50

Repository: QuantumNous/new-api

Length of output: 2222


🏁 Script executed:

echo "=== Checking Create operations for CustomOAuthProvider ===" && \
rg -n --type=go '\.Create\(|NewCustomOAuthProvider' --type=go -B 2 -A 3 | head -60

Repository: QuantumNous/new-api

Length of output: 2534


🏁 Script executed:

echo "=== Checking migrations for CustomOAuthProvider ===" && \
find . -name "*.go" -path "*/migration*" -o -path "*/migrations*" | head -10 && \
rg -n 'CustomOAuthProvider|custom_oauth_provider' --type=go | grep -i "migration\|migrate\|table" | head -20

Repository: QuantumNous/new-api

Length of output: 196


Add not null to the Enabled field for semantic clarity.

The field is currently nullable without a default constraint, which is imprecise for a feature flag. Although the creation code always explicitly sets Enabled, the column definition should enforce this intent with a not null constraint to prevent accidental NULL values if the code path changes:

Suggested fix
-	Enabled               bool   `json:"enabled"`                                                        // Whether this provider is enabled
+	Enabled               bool   `json:"enabled" gorm:"not null;default:false"`                          // Whether this provider is enabled
🤖 Prompt for AI Agents
In `@model/custom_oauth_provider.go` at line 14, The Enabled field in the
CustomOAuthProvider struct is currently nullable; update its GORM/DB struct tag
to include a NOT NULL constraint so the database enforces non-null booleans
(i.e., change the tags on the Enabled field in model/custom_oauth_provider.go to
add `not null`), and ensure any migration or schema generation will pick up the
change so the column is created/altered with NOT NULL to prevent NULL values.

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.