Skip to content

fix: allow null auto_id primary column in DataFrame insert#3673

Merged
sre-ci-robot merged 1 commit into
milvus-io:masterfrom
VectorPeak:codex/fix-auto-id-dataframe-insert
Jul 9, 2026
Merged

fix: allow null auto_id primary column in DataFrame insert#3673
sre-ci-robot merged 1 commit into
milvus-io:masterfrom
VectorPeak:codex/fix-auto-id-dataframe-insert

Conversation

@VectorPeak

Copy link
Copy Markdown
Contributor

This PR fixes a DataFrame insert validation crash when an auto_id primary key column is present but contains only null values.

What Problem This Solves

check_insert_schema() already treats an all-null auto_id primary key column as "no primary key values were provided" and tries to remove that column before validating the remaining DataFrame fields.

The current code builds a list of DataFrame column labels, but then attempts to remove the FieldSchema object itself:

columns = list(data.columns)
columns.remove(schema.primary_field)

Since data.columns contains column names, not FieldSchema objects, this raises:

ValueError: list.remove(x): x not in list

A minimal trigger is an auto_id schema with a DataFrame that keeps the primary key column but leaves it entirely null:

pd.DataFrame({
    "id": [None, None],
    "vec": [[1.0, 2.0], [3.0, 4.0]],
})

Change

Remove the primary key column by its field name instead of by the FieldSchema object:

columns.remove(schema.primary_field.name)

This keeps the existing behavior unchanged for non-null auto_id primary key values: if users explicitly provide primary key data, check_insert_schema() still raises DataNotMatchException.

Evidence

Before this fix, check_insert_schema() crashes before it can validate the remaining DataFrame fields:

ValueError: list.remove(x): x not in list

After this fix:

  • DataFrame inserts with an all-null auto_id primary key column pass schema validation.
  • DataFrame inserts with non-null auto_id primary key values are still rejected with DataNotMatchException.

Possible call chain / impact

Collection.insert(pd.DataFrame)
  -> check_insert_schema(...)
    -> auto_id primary field exists in DataFrame
    -> all primary key values are null
    -> remove auto_id primary column before validating remaining fields

This PR only changes the column removal path for all-null auto_id primary key columns in DataFrame insert validation. It does not change list-based inserts, row-based inserts, upsert validation, or the existing rejection of non-null auto_id primary key values.

Testing

  • uv run --python 3.11 --group dev pytest tests/unit/orm/test_schema.py::TestCheckInsertSchema -q
  • uv run --python 3.11 --group dev pytest tests/unit/orm/test_prepare.py -k auto_id -q
  • uv run --python 3.11 --group dev black --check pymilvus/orm/schema.py tests/unit/orm/test_schema.py
  • uv run --python 3.11 --group dev ruff check pymilvus/orm/schema.py tests/unit/orm/test_schema.py
  • git diff --check -- pymilvus/orm/schema.py tests/unit/orm/test_schema.py

@sre-ci-robot
sre-ci-robot requested review from czs007 and longjiquan July 7, 2026 10:19
@VectorPeak
VectorPeak force-pushed the codex/fix-auto-id-dataframe-insert branch from c50bc56 to 3373c79 Compare July 7, 2026 10:19
@mergify mergify Bot added the needs-dco label Jul 7, 2026
@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.02%. Comparing base (0ee0227) to head (18a0389).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3673      +/-   ##
==========================================
+ Coverage   93.93%   94.02%   +0.08%     
==========================================
  Files          72       72              
  Lines       15541    15567      +26     
==========================================
+ Hits        14599    14637      +38     
+ Misses        942      930      -12     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mergify mergify Bot added the ci-passed label Jul 7, 2026
@VectorPeak

Copy link
Copy Markdown
Contributor Author

Additional trigger context for reviewers:

This bug is not a broad DataFrame insert failure. It requires four conditions to line up:

  1. The insert path uses Collection.insert(pd.DataFrame).
  2. The collection schema has an auto_id=True primary key.
  3. The incoming DataFrame still includes the primary key column, for example id.
  4. That primary key column is entirely null (None / NaN).

In that case, check_insert_schema() already treats the all-null auto_id primary column as "no user-provided primary key values" and tries to remove it before validating the remaining fields. The crash happens because the code removes the FieldSchema object from a list of DataFrame column-name strings:

columns = list(data.columns)
columns.remove(schema.primary_field)

A realistic way to hit this is an ETL/DataFrame workflow where the source table or CSV/Parquet schema still has an id column, but new rows leave it null because Milvus is expected to generate IDs. From the user's perspective, the primary key was intentionally left empty for auto_id, so the client-side ValueError: list.remove(x): x not in list is surprising and hides the intended validation path.

@VectorPeak
VectorPeak force-pushed the codex/fix-auto-id-dataframe-insert branch from 3373c79 to 63a64ce Compare July 9, 2026 09:33
Signed-off-by: VectorPeak <73048950+VectorPeak@users.noreply.github.com>
Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
Signed-off-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
@mergify mergify Bot removed the ci-passed label Jul 9, 2026
@VectorPeak
VectorPeak force-pushed the codex/fix-auto-id-dataframe-insert branch from 63a64ce to 18a0389 Compare July 9, 2026 09:34
@mergify mergify Bot added dco-passed and removed needs-dco labels Jul 9, 2026
@mergify

mergify Bot commented Jul 9, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@XuanYang-cn XuanYang-cn 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.

/lgtm

@sre-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: VectorPeak, XuanYang-cn

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sre-ci-robot
sre-ci-robot merged commit c972e41 into milvus-io:master Jul 9, 2026
14 checks passed
@pymilvus-bot

Copy link
Copy Markdown
Collaborator

Backport Created
Hi @VectorPeak, Backport PR for 2.6 has been created: #3677

(cc @XuanYang-cn)

@pymilvus-bot

Copy link
Copy Markdown
Collaborator

Backport Created
Hi @VectorPeak, Backport PR for 3.0 has been created: #3678

(cc @XuanYang-cn)

sre-ci-robot pushed a commit that referenced this pull request Jul 14, 2026
…sert (#3673) (#3678)

Backport of #3673 to `3.0`.

Signed-off-by: VectorPeak <73048950+VectorPeak@users.noreply.github.com>
Signed-off-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
Signed-off-by: pymilvus-bot <pymilvus-bot@users.noreply.github.com>
Co-authored-by: VectorPeak <garrufariw@gmail.com>
Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
sre-ci-robot pushed a commit that referenced this pull request Jul 14, 2026
…sert (#3673) (#3677)

Backport of #3673 to `2.6`.

Signed-off-by: VectorPeak <73048950+VectorPeak@users.noreply.github.com>
Signed-off-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
Signed-off-by: pymilvus-bot <pymilvus-bot@users.noreply.github.com>
Co-authored-by: VectorPeak <garrufariw@gmail.com>
Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants