Skip to content

fix(notion): improve trigger polling logic and resolve database loadi…#28480

Open
dev-frog wants to merge 1 commit inton8n-io:masterfrom
dev-frog:fix/notion-trigger-duplicate-id-28463
Open

fix(notion): improve trigger polling logic and resolve database loadi…#28480
dev-frog wants to merge 1 commit inton8n-io:masterfrom
dev-frog:fix/notion-trigger-duplicate-id-28463

Conversation

@dev-frog
Copy link
Copy Markdown

…ng error #28463

Summary

This PR fixes two major issues with the Notion Trigger:

  1. Duplicate Executions: Resolved an issue where the trigger fetched the same items repeatedly due to Notion's minute-level timestamp accuracy and a "Greater Than or Equal To" filter logic.
  2. UI Loading Errors: Fixed a "can't get data for expression" error in the getDatabases load option by making the resource parameter optional in notionApiRequestAllItems.

Changes

  • State Management: Switched lastTimeChecked from a Moment object to an ISO String for reliable persistence in staticData.
  • Atomic Updates: The polling timestamp now updates at the end of a successful poll rather than the beginning.
  • Duplicate Filtering: Improved the possibleDuplicates logic to track IDs within the same minute window, preventing re-processing of items Notion returns during high-frequency polling.
  • Generic Function Fix: Updated notionApiRequestAllItems in GenericFunctions.ts to prevent crashes when called from triggers/load-options where a specific resource context is missing.

Testing

  • Verified with a local n8n instance and a Notion test database.
  • Confirmed that multiple edits within the same minute no longer trigger duplicate workflows.
  • Confirmed that the "Database" dropdown in the node UI now loads correctly without errors.

Related Issues

Fixes #28463
Internal Ref: GHC-7732

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

Architecture diagram
sequenceDiagram
    participant UI as Editor UI
    participant Trigger as Notion Trigger Node
    participant GF as Generic Functions
    participant Store as Static Data Store
    participant Notion as Notion API

    Note over UI, Notion: UI Loading Flow (Fixes "can't get data" error)
    UI->>Trigger: Request Load Options (e.g., getDatabases)
    Trigger->>GF: notionApiRequestAllItems()
    GF->>GF: NEW: Safe-fetch 'resource' parameter (defaults undefined)
    GF->>Notion: Request metadata/resources
    Notion-->>UI: Return list for dropdown

    Note over UI, Notion: Polling Execution (Fixes Duplicate Logic)
    Trigger->>Store: Get lastTimeChecked & possibleDuplicates
    Trigger->>Notion: Query DB (timestamp >= lastTimeChecked)
    Notion-->>Trigger: Return records (Minute-level precision)

    Trigger->>Trigger: Filter out IDs present in possibleDuplicates
    
    alt NEW: Current records fall within same minute as last poll
        Trigger->>Trigger: NEW: Append new IDs to possibleDuplicates list
    else NEW: Most recent record is a new minute window
        Trigger->>Trigger: NEW: Replace possibleDuplicates with new IDs
    end

    Trigger->>Store: CHANGED: Persist lastTimeChecked as ISO String (only on success)
    Trigger-->>UI: Output unique records to workflow
Loading

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.

The Notion trigger in n8n is not working, even though I’ve created everything again.

1 participant