Skip to content

improvement(api): fix default value not actually updated if no value provided for the i…#5482

Merged
maidul98 merged 2 commits intomainfrom
ENG-4569-fix-oudated-default-value-for-clickhouse-insert-settings
Feb 14, 2026
Merged

improvement(api): fix default value not actually updated if no value provided for the i…#5482
maidul98 merged 2 commits intomainfrom
ENG-4569-fix-oudated-default-value-for-clickhouse-insert-settings

Conversation

@fangpenlin
Copy link
Contributor

…nsert settings issue

Context

https://linear.app/infisical/issue/ENG-4569/update-backend-to-make-audit-query-send-to-clickhouse-based-on

Steps to verify the change

Type

  • Fix
  • Feature
  • Improvement
  • Breaking
  • Docs
  • Chore

Checklist

  • Title follows the conventional commit format: type(scope): short description (scope is optional, e.g., fix: prevent crash on sync or fix(api): handle null response).
  • Tested locally
  • Updated docs (if needed)
  • Read the contributing guide

@linear
Copy link

linear bot commented Feb 14, 2026

@maidul98
Copy link
Collaborator

maidul98 commented Feb 14, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@fangpenlin fangpenlin marked this pull request as ready for review February 14, 2026 01:34
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 14, 2026

Greptile Overview

Greptile Summary

This PR fixes a bug where the CLICKHOUSE_AUDIT_LOG_INSERT_SETTINGS environment variable defaults were not being applied correctly. Previously, when using Zod's .default() with a .transform(), the default value wasn't used when the environment variable was empty or unset, causing the transformation to return incorrect default values.

Key Changes:

  • Extracted DEFAULT_CLICKHOUSE_AUDIT_LOG_INSERT_SETTINGS as a constant at module level
  • Changed .default() to use JSON.stringify() of the constant, ensuring the default is applied after transformation
  • Changed ClickHouse audit log insert to use auditLog.createdAt from PostgreSQL instead of new Date(), ensuring timestamp consistency between both databases for easier deduplication
  • Added explanatory comments for both id and createdAt synchronization

Technical Context:
When Zod's .transform() is applied before .default(), the transformation runs first even for undefined/empty values, so the inline object literal default was never used. By extracting to a constant and using JSON.stringify() in the default, the chain now works correctly: empty values are caught by the transformation, which returns the constant, and the stringified constant serves as the actual default value.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are well-focused bug fixes that improve data consistency. The refactoring extracts defaults to a constant (better maintainability), and using auditLog.createdAt from PostgreSQL ensures timestamps match between databases. Both changes are backwards-compatible and don't introduce breaking changes.
  • No files require special attention

Important Files Changed

Filename Overview
backend/src/lib/config/env.ts Extracts ClickHouse default settings to constant, fixing bug where .default() didn't apply default values during transformation
backend/src/ee/services/audit-log/audit-log-queue.ts Uses PostgreSQL auditLog.createdAt instead of new Date() for ClickHouse insert, ensuring consistent timestamps for deduplication

Last reviewed commit: 00853fe

@fangpenlin fangpenlin marked this pull request as draft February 14, 2026 02:26
@fangpenlin fangpenlin marked this pull request as ready for review February 14, 2026 02:33
@maidul98 maidul98 merged commit 48646e6 into main Feb 14, 2026
11 checks passed
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.

2 participants