Skip to content

feat: implement upsert and delete [FC-0144] - #32

Merged
bradenmacdonald merged 29 commits into
openedx:mainfrom
open-craft:rpenido/FAL-4404/upsert-delete-api
Dec 4, 2026
Merged

bradenmacdonald merged 29 commits into
openedx:mainfrom
open-craft:rpenido/FAL-4404/upsert-delete-api

Conversation

@rpenido

@rpenido rpenido commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Description

Implements the write half of the consumer API on top of the contract in #20: the adapter registry, document validation, upsert, delete and check_write.

The registry resolves the configured backend's engine, builds the adapter from the registration and the resolved BackendConfig, and raises AdapterNotRegistered when the engine has no factory. Registrations and adapters are cleared between tests; neither registry is part of the consumer surface.

Document validation runs before any adapter call, so both engines accept and reject the same documents. Every required field must be present; unknown fields (including a flat key with a dot, which is not a nested field), null values, wrong types and shapes, and naive datetimes are rejected. Datetimes are accepted as aware values or POSIX seconds, the document id must match the engine-safe pattern and fit the filterable limit, and free-form object values must be strings. A violation raises DocumentError naming the document, the field and the reason.

upsert takes one bounded sequence, validates it and returns the adapter's WriteReceipt. delete takes primary keys or the abstract filter expression, never both and never neither, rejects a raw string filter and an empty filter, normalizes a single key to a tuple and validates every key.

check_write performs one status poll for a submitted write and never sleeps or retries; scheduling and backoff belong to the indexing worker. A synchronous engine returns an already-complete receipt.

The optional rebuild target is already on upsert and delete, but the dual-write orchestration lands with the rebuild lifecycle; until then the library submits to the live index only.

Testing instructions

  • Run the suite with uv run --group test pytest -q, and the linters with uv run tox -e quality.
  • These are library functions with no engine adapter on this branch; the tests use a recording adapter to check what reaches the adapter and what fails validation before it.

Additional Information

Used by:


Private ref:

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Nov 24, 2026
@openedx-webhooks

openedx-webhooks commented Nov 24, 2026 •

Copy link
Copy Markdown

Thanks for the pull request, @rpenido!

This repository is currently maintained by @ormsbee.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@rpenido
rpenido force-pushed the rpenido/FAL-4404/upsert-delete-api branch from 9688ff9 to c68b3fb Compare November 24, 2026 15:32
@rpenido rpenido changed the title feat: implement upsert and delete feat: implement upsert and delete [FC-0144] Nov 24, 2026
@rpenido rpenido moved this from Todo to In Progress in Search Improvements (FC-0144) Nov 24, 2026
@rpenido
rpenido marked this pull request as ready for review November 24, 2026 19:48
@mphilbrick211 mphilbrick211 added the FC Relates to an Axim Funded Contribution project label Nov 25, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions Nov 25, 2026

@navinkarkera navinkarkera 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.

@rpenido Overall looks good. Just some suggestions

Comment thread src/openedx_search/documents.py Resolved
Comment thread src/openedx_search/documents.py Resolved
Comment thread src/openedx_search/api.py Resolved
Comment thread tests/test_api.py Resolved
Comment thread tests/test_adapters.py Resolved
Comment thread tests/test_documents.py Resolved
Comment thread tests/fakes.py Resolved
@rpenido

rpenido commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @blarghmatey! This is ready for another round!

@rpenido

rpenido commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Hi @bradenmacdonald! Can I get your review here?

@bradenmacdonald bradenmacdonald left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks great! My comments are all pretty minor, mostly code clarity and lints. Feel free to reject or ignore any that you don't want to do.

Comment thread src/openedx_search/adapters.py Resolved
Comment thread src/openedx_search/adapters.py Resolved
Comment thread src/openedx_search/adapters.py Resolved
Comment thread src/openedx_search/adapters.py Resolved
Comment thread src/openedx_search/api.py Resolved
Comment thread tests/test_api.py Resolved
Comment thread tests/test_documents.py Resolved
Comment thread tests/test_documents.py Resolved
Comment thread tests/test_documents.py Resolved
Comment thread tests/test_schema.py Resolved
rpenido and others added 7 commits December 4, 2026 10:57
Co-authored-by: Braden MacDonald <mail@bradenm.com>
Type checks now raise TypeError; value checks such as empty sequences, invalid names and naive datetimes stay ValueError. Also removes the duplicate type aliases and the docstring whitespace left by the previous review commit.
@rpenido
rpenido force-pushed the rpenido/FAL-4404/upsert-delete-api branch 2 times, most recently from 5335110 to 1e3f18b Compare December 4, 2026 18:32
Derive the parent name from the prefix, rename inside_array to inside_object_array and explain the Typesense array rule in the validator. Also apply the adapter-registry docstring from the review.
@rpenido
rpenido force-pushed the rpenido/FAL-4404/upsert-delete-api branch from 5538b75 to 4b26bf9 Compare December 4, 2026 18:40
Add -> None to every test function and type the fixtures, so mypy checks them. The test parameters that use fake_adapter are typed as FakeAdapter.
@rpenido
rpenido force-pushed the rpenido/FAL-4404/upsert-delete-api branch from 92d5052 to 4071d41 Compare December 4, 2026 19:05
@rpenido

rpenido commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review @bradenmacdonald! I think I addressed all your comments.

@bradenmacdonald bradenmacdonald left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks, looks great! Merging now to unblock the stack. We can always refine the API as needed during later PRs too.

@bradenmacdonald
bradenmacdonald merged commit 1cb66e6 into openedx:main Dec 4, 2026
10 checks passed
@github-project-automation github-project-automation Bot moved this from Ready for Review to Done in Contributions Dec 4, 2026
@bradenmacdonald
bradenmacdonald deleted the rpenido/FAL-4404/upsert-delete-api branch December 4, 2026 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

FC Relates to an Axim Funded Contribution project open-source-contribution PR author is not from Axim or 2U

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Async API for confirming upsert write was completed Python API to upsert and delete documents (in batch or singular)

6 participants