Skip to content

Fix missing creation attributes#15624

Merged
martmull merged 1 commit intomainfrom
fix-application-sync-serverless-function-create
Nov 5, 2025
Merged

Fix missing creation attributes#15624
martmull merged 1 commit intomainfrom
fix-application-sync-serverless-function-create

Conversation

@martmull
Copy link
Copy Markdown
Contributor

@martmull martmull commented Nov 5, 2025

Fixes serverlessFucntion are created with default handlerPath and handlerName values

Comment on lines +33 to +36
handlerPath:
rawCreateServerlessFunctionInput.handlerPath ?? DEFAULT_HANDLER_PATH,
handlerName:
rawCreateServerlessFunctionInput.handlerName ?? DEFAULT_HANDLER_NAME,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Empty strings for handlerPath or handlerName bypass default fallbacks, leading to esbuild failures during serverless function execution.
Severity: CRITICAL | Confidence: 0.98

🔍 Detailed Analysis

The system allows empty strings for handlerPath or handlerName fields because @IsString() validation does not prevent them, and the nullish coalescing operator ?? does not trigger fallbacks for empty strings. When a client provides an empty string for handlerPath, it is persisted to the database. During serverless function execution, buildServerlessFunctionInMemory uses this empty handlerPath, causing join(sourceTemporaryDir, handlerPath) to resolve to a directory. esbuild then fails to build the function because the entry point is a directory instead of a file.

💡 Suggested Fix

Add @MinLength(1) to the DTO fields for handlerPath and handlerName, or modify the utility to use a more robust fallback pattern like rawCreateServerlessFunctionInput.handlerPath?.trim() || DEFAULT_HANDLER_PATH.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location:
packages/twenty-server/src/engine/metadata-modules/serverless-function/utils/from-create-serverless-function-input-to-flat-serverless-function.util.ts#L33-L36

Potential issue: The system allows empty strings for `handlerPath` or `handlerName`
fields because `@IsString()` validation does not prevent them, and the nullish
coalescing operator `??` does not trigger fallbacks for empty strings. When a client
provides an empty string for `handlerPath`, it is persisted to the database. During
serverless function execution, `buildServerlessFunctionInMemory` uses this empty
`handlerPath`, causing `join(sourceTemporaryDir, handlerPath)` to resolve to a
directory. `esbuild` then fails to build the function because the entry point is a
directory instead of a file.

Did we get this right? 👍 / 👎 to inform future reviews.

@martmull martmull force-pushed the fix-application-sync-serverless-function-create branch from e6a5fc6 to 70bd6a5 Compare November 5, 2025 08:18
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Greptile Summary

Added optional handlerPath and handlerName fields to serverless function creation, allowing users to override default handler configuration while maintaining backward compatibility.

Key changes:

  • Added handlerPath and handlerName as optional string fields in CreateServerlessFunctionInput DTO with proper validation decorators
  • Updated transformation utility to use provided values or fall back to DEFAULT_HANDLER_PATH (src/index.ts) and DEFAULT_HANDLER_NAME (main)
  • Maintains consistency with existing update functionality where these fields are already supported

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are straightforward, well-scoped, and maintain backward compatibility. Optional fields with proper defaults ensure existing functionality is unaffected. The implementation pattern matches the existing update DTO, demonstrating consistency across the codebase.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
packages/twenty-server/src/engine/metadata-modules/serverless-function/dtos/create-serverless-function.input.ts 5/5 Added optional handlerName and handlerPath fields to allow custom handler configuration during serverless function creation
packages/twenty-server/src/engine/metadata-modules/serverless-function/utils/from-create-serverless-function-input-to-flat-serverless-function.util.ts 5/5 Updated transformation logic to use custom handlerPath and handlerName from input, falling back to defaults when not provided

Sequence Diagram

sequenceDiagram
    participant Client
    participant CreateServerlessFunctionInput
    participant TransformUtil
    participant FlatServerlessFunction
    participant Database

    Client->>CreateServerlessFunctionInput: Create with optional handlerPath & handlerName
    Note over CreateServerlessFunctionInput: Validates string fields<br/>handlerPath (optional)<br/>handlerName (optional)
    CreateServerlessFunctionInput->>TransformUtil: fromCreateServerlessFunctionInputToFlatServerlessFunction()
    Note over TransformUtil: handlerPath = input.handlerPath ?? DEFAULT_HANDLER_PATH<br/>handlerName = input.handlerName ?? DEFAULT_HANDLER_NAME
    TransformUtil->>FlatServerlessFunction: Create flat object
    FlatServerlessFunction->>Database: Persist with handler values
Loading

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link
Copy Markdown
Member

@Weiko Weiko left a comment

Choose a reason for hiding this comment

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

You probably want some kind of validation otherwise LGTM

@martmull martmull enabled auto-merge (squash) November 5, 2025 08:23
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Nov 5, 2025

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:6189

This environment will automatically shut down when the PR is closed or after 5 hours.

@martmull martmull merged commit 642e0c8 into main Nov 5, 2025
64 of 65 checks passed
@martmull martmull deleted the fix-application-sync-serverless-function-create branch November 5, 2025 08:29
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