Fix/pickle whitelist zscore#2230
Open
Olcmyk wants to merge 3 commits into
Open
Conversation
…aset chain The RestrictedUnpickler safelist introduced by the recent security hardening (microsoft#2099 / microsoft#2076 / microsoft#2153) only covered the abstract ``DataHandler`` / ``DataHandlerLP`` classes plus ``StaticDataLoader``. Any rolling workflow that pickles a real Dataset (the default for ``Rolling._train_rolling_tasks``) walks into one of the contrib stock handlers and now crashes on reload (issue microsoft#2130): UnpicklingError: Forbidden class: qlib.contrib.data.handler.Alpha158. Only whitelisted classes are allowed for security reasons. ... Unrolling workflows happened to use a path that did not go through the restricted loader, which is why downgrading to 0.9.7 hid the issue. Extend ``SAFE_PICKLE_CLASSES`` with the qlib-internal classes that sit on the standard recorder pickle graph: * The four shipped contrib handlers: ``Alpha158``, ``Alpha158vwap``, ``Alpha360``, ``Alpha360vwap``. * The dataset wrappers (``Dataset``, ``DatasetH``, ``TSDatasetH``) and the additional concrete loaders (``DataLoader``, ``DLWParser``, ``QlibDataLoader``, ``NestedDataLoader``, ``DataLoaderDH``). * Every concrete ``Processor`` defined in ``qlib.data.dataset.processor`` -- they show up in every realistic ``learn_processors`` / ``infer_processors`` chain. These are all classes already shipped inside qlib itself, so adding them does not weaken the threat model the safelist was designed against (arbitrary code execution through external pickle payloads). Add regression tests pinning each added entry plus an end-to-end check that ``RestrictedUnpickler.find_class`` actually resolves ``Alpha158`` and that other unknown classes are still rejected. Fixes microsoft#2130
PR microsoft#2213 added Alpha158/Alpha360 handlers to the pickle whitelist but missed qlib.utils.data.zscore, which is also required by the DDG-DA workflow. Without this, DDG-DA fails with: UnpicklingError: Forbidden class: qlib.utils.data.zscore This commit adds zscore to the whitelist and includes a test to prevent regression. Fixes microsoft#2130 (supplement to PR microsoft#2213)
Author
@microsoft-github-policy-service agree |
Author
|
@microsoft-github-policy-service agree |
This was referenced May 23, 2026
Olcmyk
added a commit
to Olcmyk/qlib
that referenced
this pull request
May 23, 2026
…sues
This commit fixes two critical bugs that prevented DDG-DA workflow from running:
1. **Unhashable list type error in InternalData.setup()**
- Problem: data_key was a list [start_date, end_date], which cannot be used
as dictionary keys or DataFrame column names
- Fix: Convert list to tuple to make it hashable (line 99-100)
2. **Incorrect pandas indexing in _calc_perf()**
- Problem: Used wrong syntax df.loc(axis=0)[:, "pred"] and group_keys=False
caused loss of datetime index, leading to droplevel error
- Fix: Remove group_keys=False and use df.xs("label", level=1) to correctly
select from MultiIndex (line 112-114)
3. **Missing InternalData in pickle whitelist**
- Problem: InternalData class was not whitelisted, causing UnpicklingError
- Fix: Add InternalData to SAFE_PICKLE_CLASSES (pickle_utils.py line 91)
Changes:
- qlib/contrib/meta/data_selection/dataset.py:
* Convert list to tuple for hashable dictionary keys
* Fix _calc_perf to use correct pandas MultiIndex selection
- qlib/utils/pickle_utils.py:
* Add InternalData to pickle whitelist
Testing:
✅ DDG-DA workflow now runs successfully to completion
✅ All 154 training tasks complete without errors
✅ Meta-learning data selection works correctly
✅ Final backtest results generated successfully
This is a WORKING VERSION - DDG-DA workflow runs end-to-end!
Related issues:
- Depends on PR microsoft#2230 (zscore whitelist)
- Depends on LightGBM 4.0+ compatibility fix
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
DDG-DA workflow pickles and reloads InternalData objects during meta-learning
data selection. Without this whitelist entry, the workflow fails with:
UnpicklingError: Forbidden class: qlib.contrib.meta.data_selection.dataset.InternalData
Changes:
- Add InternalData to SAFE_PICKLE_CLASSES in qlib/utils/pickle_utils.py
- Add test case test_internal_data_is_safelisted to verify the whitelist entry
This is part of the fix for issue microsoft#2130 - DDG-DA workflow requires multiple
classes to be whitelisted for pickle deserialization.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR supplements PR #2213 by adding
qlib.utils.data.zscoreto the pickle whitelist.PR #2213 successfully added
Alpha158andAlpha360handlers to fix issue #2130, but the whitelist is still incomplete. The DDG-DA workflow also requireszscoreto be whitelisted, otherwise it fails immediately after the Alpha handlers are loaded.Changes:
("qlib.utils.data", "zscore")toSAFE_PICKLE_CLASSESinqlib/utils/pickle_utils.pytest_zscore_is_safelistedto prevent regressionMotivation and Context
Fixes #2130 (supplement to PR #2213)
Problem: After applying PR #2213, the DDG-DA workflow still fails with:
Root cause: The
zscoreutility function is used in data processing and gets pickled with the dataset, but it was not included in PR #2213's whitelist additions.How to Reproduce the Issue (Before This Fix)
cd examples/benchmarks_dynamic/DDG-DA rm -rf mlruns python workflow.py runExpected error:
How Has This Been Tested?
python -m unittest tests.misc.test_pickle_safelist -vTesting environment:
Test results:
Manual verification:
After applying this fix and reinstalling (
pip install -e .), the DDG-DA workflow successfully loads the dataset and proceeds to the next stage (LightGBM training).Types of changes
Additional Notes
This is a minimal, focused fix that adds only the missing
zscoreclass to the whitelist established by PR #2213. The fix follows the same pattern and includes a test case consistent with the existing test structure.Relationship to PR #2213:
References