Skip to content

Conversation

ml-evs
Copy link
Member

@ml-evs ml-evs commented Aug 12, 2025

This PR initially just updated the "all blocks" test to separate out each block and make sure that they were all doing something sensible. However, I realised that without the app to pass block data back in update-block calls, some of the block results was not being saved in the database. This PR fixes that by explicitly calling _save_to_db after every block creation call, making the save_to_db option somewhat defunct.

Following the principle of least suprise, I think the previous undocumented behaviour (i.e., being able to essentially see a block in an unsaved state) was not expected, so the only side effect here should be improved persistence.

In order to properly implement this, block operations now go through the new DataBlockResponse model introduced in #1310, which we can refine over time. I've refactored the NMR, XRD and ChatBlock to extend and use this model directly. No other blocks should be affected, as of yet, as the model still allows extra keys to be passed through transparently. A future PR will have to try restrict this and refactor all blocks to store data in the correct places whilst maintaining backwards compat.

Copy link

cypress bot commented Aug 12, 2025

datalab    Run #3772

Run Properties:  status check passed Passed #3772  •  git commit 6c11615e40 ℹ️: Merge c714e70a53babb796fbb330d2557a445dd1430d1 into 93441d3dbef9cd8c2671aaf2c08b...
Project datalab
Branch Review ml-evs/improve-block-test
Run status status check passed Passed #3772
Run duration 08m 01s
Commit git commit 6c11615e40 ℹ️: Merge c714e70a53babb796fbb330d2557a445dd1430d1 into 93441d3dbef9cd8c2671aaf2c08b...
Committer Matthew Evans
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 336
View all changes introduced in this branch ↗︎

@ml-evs ml-evs force-pushed the ml-evs/improve-block-test branch 2 times, most recently from d9f3b67 to 55683e4 Compare August 12, 2025 20:13
Copy link

codecov bot commented Aug 12, 2025

Codecov Report

❌ Patch coverage is 86.88525% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.82%. Comparing base (93441d3) to head (c714e70).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
pydatalab/src/pydatalab/apps/chat/blocks.py 77.61% 15 Missing ⚠️
pydatalab/src/pydatalab/apps/nmr/blocks.py 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1311      +/-   ##
==========================================
+ Coverage   78.90%   79.82%   +0.91%     
==========================================
  Files          68       69       +1     
  Lines        4679     4674       -5     
==========================================
+ Hits         3692     3731      +39     
+ Misses        987      943      -44     
Files with missing lines Coverage Δ
pydatalab/src/pydatalab/apps/chat/models.py 100.00% <100.00%> (ø)
pydatalab/src/pydatalab/apps/xrd/blocks.py 82.58% <100.00%> (-2.65%) ⬇️
pydatalab/src/pydatalab/blocks/base.py 94.02% <100.00%> (+4.30%) ⬆️
pydatalab/src/pydatalab/models/blocks.py 100.00% <100.00%> (ø)
pydatalab/src/pydatalab/routes/v0_1/blocks.py 65.55% <100.00%> (-1.12%) ⬇️
pydatalab/src/pydatalab/routes/v0_1/items.py 86.28% <100.00%> (+3.38%) ⬆️
pydatalab/src/pydatalab/apps/nmr/blocks.py 86.75% <87.50%> (+0.08%) ⬆️
pydatalab/src/pydatalab/apps/chat/blocks.py 75.59% <77.61%> (+17.52%) ⬆️

... and 1 file with indirect coverage changes

🚀 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.

@ml-evs ml-evs force-pushed the ml-evs/improve-block-test branch from 55683e4 to 399ae9d Compare August 13, 2025 12:36
@ml-evs ml-evs changed the title Refactor all block test into parameterized loop and tweak block db lifecycle Validate block database save/export operations with DataBlockResponse model Aug 13, 2025
@ml-evs ml-evs force-pushed the ml-evs/improve-block-test branch 2 times, most recently from 7c77647 to 8fd6785 Compare August 13, 2025 15:56
@ml-evs ml-evs force-pushed the ml-evs/improve-block-test branch 2 times, most recently from b7a8008 to 2d68baf Compare August 19, 2025 21:57
@ml-evs
Copy link
Member Author

ml-evs commented Aug 19, 2025

This is the first of several scary technical debt resolving PRs, with this one changing how we save block data -- I've tried to test the current behaviour extensively so that we know when we are breaking it, but will need several follow-ups to refine it. Next up, trying to get pydantic v2 in... this PR started as an off-shoot for that to just robustify some of the tests!

@ml-evs ml-evs added API For issues/PRs pertaining to the API refactoring For issues/PRs that refactor existing code/features datablock An issue pertaining to a specific datablock schema For issues/PRs pertaining to data models and schemas labels Aug 19, 2025
@ml-evs ml-evs requested a review from jdbocarsly August 19, 2025 22:00
@ml-evs
Copy link
Member Author

ml-evs commented Aug 19, 2025

As our premier chat block user @jdbocarsly, I wonder if you just want to try out the refactored chat block locally after I merge this? I've significantly refactored it and added a lot of extra validation, plus a testing mode that uses Langchain's FakeLLM models, so I hope its now more robust than ever...

@ml-evs ml-evs force-pushed the ml-evs/improve-block-test branch 2 times, most recently from 23a0ffe to ee9278c Compare August 19, 2025 22:24
@ml-evs ml-evs force-pushed the ml-evs/improve-block-test branch 7 times, most recently from ed4cc63 to 10b4953 Compare August 20, 2025 23:31
@ml-evs ml-evs force-pushed the ml-evs/improve-block-test branch from 10b4953 to 3500700 Compare August 20, 2025 23:45
ml-evs added 2 commits August 21, 2025 01:01
- Do not mutate block state when saving to db

- Make sure block db update happens twice: once after receiving partial UI state, and once after block run
@ml-evs ml-evs force-pushed the ml-evs/improve-block-test branch from 3500700 to 8f0bb79 Compare August 21, 2025 00:09
ml-evs added 4 commits August 21, 2025 01:17
- Nest XRD peak data under processed_data key

- Add some verbose tests for block life cycle

- Add metadata to block model

- Remove defunct code for from_db, dereference_files and load_blocks

- Strip potentially heavy ignored keys out of item save from app and API

- Add metadata field for blocks

- Use strings for file ID keys in nested block fields

- Reintroduce uv-vis test

- Fix issue where bokeh plot disappears after save
@ml-evs ml-evs force-pushed the ml-evs/improve-block-test branch from 8f0bb79 to c714e70 Compare August 21, 2025 00:17
@ml-evs ml-evs merged commit 0871c95 into main Aug 21, 2025
15 checks passed
@ml-evs ml-evs deleted the ml-evs/improve-block-test branch August 21, 2025 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API For issues/PRs pertaining to the API datablock An issue pertaining to a specific datablock refactoring For issues/PRs that refactor existing code/features schema For issues/PRs pertaining to data models and schemas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants