Skip to content

Conversation

be-smith
Copy link
Contributor

No description provided.

… and save the same version. Added better error handling for if an invalid id is used
Adds deepdiff ~= 8.1 to project dependencies to enable proper
comparison of nested dictionaries and lists in version control
functionality.
Replaces simple dict_diff function with DeepDiff library to properly
handle nested dictionaries, lists, type changes, and provide detailed
change information for version comparisons.
Adds comprehensive safety checks to restore_version:
- Permissions check requiring write access
- Protected fields list preventing restoration of critical system fields
  (refcode, _id, immutable_id, creator_ids, file_ObjectIds, version)
- Type consistency check preventing cross-type restoration
- Model validation ensuring restored data passes schema validation
- Atomic version incrementing using shared counter to prevent collisions

The version field now always increments forward to avoid duplicate
version numbers when restoring and then making subsequent changes.
Adds action field to track why each version was created:
- 'manual_save': User explicitly saved (save-version endpoint or save-item)
- 'auto_save': Reserved for future block-triggered auto-saves
- 'pre_restore_backup': System backup created before restoring

Refactored version saving into _save_version_snapshot() helper function
that can be called with different action parameters. The restore_version
endpoint also tracks which version was restored to via restored_from_version field.
Changes save_item to update the item BEFORE saving the version snapshot,
preventing orphaned versions if the item update fails.

Previously: save version → update item (if item update failed, orphaned version)
Now: update item → save version (if version save fails, item is still saved)

If version save fails after successful item update, the error is logged
but the request still succeeds since the user's work has been saved.
Add version field to the HasRevisionControl Pydantic model to support
the version control system's snapshot tracking. Fix the save_item
endpoint to correctly increment version by adding it to updated_data
rather than the discarded item object.
Add 33 tests covering all version control functionality:
- Save, list, get, compare, restore, and delete version endpoints
- Auto-versioning on save_item
- Atomic version counter with race condition prevention
- Protected field validation during restore
- Permissions enforcement
- Error handling and edge cases
- Add action and restored_from_version fields to list_versions endpoint
- Change restore to create version snapshot AFTER restoring (not before)
- Version snapshot now contains the restored data for clearer audit trail
- Update action type from "pre_restore_backup" to "restored"
- Add version control API service methods to server_fetch_utils.js
- Create VersionHistoryModal component for viewing and managing versions
- Add version history button to EditPage navbar
- Support version preview and restore functionality with proper state management
- Add new TestActionFields class with 5 tests validating action values
- Test manual_save action from save-version endpoint
- Test manual_save action from save-item endpoint (user saves)
- Test restored action with restored_from_version reference
- Test that restored version snapshots contain the restored data
- Test complete audit trail across multiple saves and restore
- Rename test_list_versions_action_field to be more descriptive
- Update test_restore_version_creates_backup to _creates_snapshot
- Remove duplicate action field tests from TestRestoreVersion class
- Fix unused variable in test_get_version_success
@be-smith be-smith changed the title Bes/revision history clean history Adding version control to samples, starting materials and cells Oct 13, 2025
Copy link

codecov bot commented Oct 13, 2025

Codecov Report

❌ Patch coverage is 96.15385% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.43%. Comparing base (767e66d) to head (208402d).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
pydatalab/src/pydatalab/routes/v0_1/items.py 96.09% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1373      +/-   ##
==========================================
+ Coverage   80.06%   80.43%   +0.37%     
==========================================
  Files          70       70              
  Lines        4731     4877     +146     
==========================================
+ Hits         3788     3923     +135     
- Misses        943      954      +11     
Files with missing lines Coverage Δ
pydatalab/src/pydatalab/models/traits.py 98.68% <100.00%> (+0.03%) ⬆️
pydatalab/src/pydatalab/routes/v0_1/items.py 88.13% <96.09%> (+1.85%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

cypress bot commented Oct 13, 2025

datalab    Run #3941

Run Properties:  status check passed Passed #3941  •  git commit e6ac83e3c0 ℹ️: Merge 208402d35d3ccc62f45a4ae77b703dd144cf868e into b121182e7a2c4ca1eebd268ed0b8...
Project datalab
Branch Review bes/revision_history_clean_history
Run status status check passed Passed #3941
Run duration 06m 35s
Commit git commit e6ac83e3c0 ℹ️: Merge 208402d35d3ccc62f45a4ae77b703dd144cf868e into b121182e7a2c4ca1eebd268ed0b8...
Committer Ben Smith
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 168
View all changes introduced in this branch ↗︎

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.

1 participant