Skip to content

Built-in metadata written at document creation uses a different format, breaking time filters on upload_date / last_update_date #44217

Closed

Description

@cty-ut

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.17.1 (also present on main @ 69e9ca4)

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

  1. Create a knowledge base and upload a document (e.g. a.pdf).
  2. Open the knowledge base metadata settings and enable Built-in metadata.
  3. Upload another document (e.g. b.pdf).
  4. In a workflow / chatflow, add a Knowledge Retrieval node with manual metadata filtering: upload_date after any date.
  5. Run it.

Root cause: built-in fields are written by three code paths, and they don't agree on the format:

Writer upload_date / last_update_date source
SQLAlchemyMetadataRepository._built_in (enabling built-in fields, batch metadata edit) epoch seconds, e.g. 1760601600.0 MetadataDataSource label, e.g. file_upload
DocumentService.build_document (documents created after built-in fields are enabled) "2026-10-16 08:00:00" (string) raw data_source_type, e.g. upload_file
PipelineGenerator._build_document (knowledge pipeline, copied from the above) same string same raw value

time filters compile to CAST(doc_metadata ->> 'upload_date' AS FLOAT), so a single string-formatted document makes the whole query fail on PostgreSQL. I ran the SQL produced by DatasetRetrieval.process_metadata_filter_func against a minimal documents table on PostgreSQL 15 holding one row in each format:

upload_date before 1893456000 -> InvalidTextRepresentation: invalid input syntax for type double precision: "2026-10-16 08:00:00"
upload_date after 0           -> InvalidTextRepresentation: invalid input syntax for type double precision: "2026-10-16 08:00:00"
source is 'file_upload'       -> only the document written by _built_in is returned

(Verified at the SQL level with Dify's own filter function, not through a full end-to-end deployment.)

Both formats were introduced together in #15982; the knowledge pipeline later copied the build_document version in #25360.

✔️ Expected Behavior

Every document stores built-in fields in the same format: epoch seconds for the time fields and the MetadataDataSource label for source, the same label the document detail page shows (format_document_built_in_fields). Time filters and source filters then work for all documents.

❌ Actual Behavior

  • Filtering on upload_date / last_update_date with before / after / < / > fails the Knowledge Retrieval node with a PostgreSQL cast error once any document has been created after built-in fields were enabled.
  • Filtering source is file_upload (the value shown in the UI) silently skips those documents, because they store upload_file.

I'd like to submit a fix for this.

Activity

  1. dosubot commented on Oct 16, 2026

    @dosubot

    Hi @cty-ut! I'm Dosu and I'm helping the Dify team.
    Thanks for the detailed reproduction. The checked-out code matches the mismatch you described: both creation paths write formatted date strings and raw source values, while _built_in writes numeric timestamps and mapped source labels. [1] [2] [3]

    For your fix, I’d suggest regression coverage across all three writers, asserting the same stored types and source labels, plus PostgreSQL retrieval tests for both date fields and source equality. The filter implementation uses .as_float() for date comparisons, so testing only the generated metadata would miss the failing query behavior. [4]

    One scope point to flag for maintainers: correcting the creation paths alone would leave previously stored malformed values untouched, since these assignments apply to newly constructed documents. Please include that existing-data concern in the fix description so maintainers can decide on an official migration strategy. [5] [6]

    To reply, just mention @dosu.


    Docs are dead. Just use Dosu.

    Leave Feedback Ask Dosu about dify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    review: mediumghfind author score; see https://ghfind.com

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions