Skip to content

fix(streamlit): read state logs as utf-8 - #907

Open
Ghraven wants to merge 3 commits into
apache:mainfrom
Ghraven:fix/streamlit-log-utf8
Open

Ghraven wants to merge 3 commits into
apache:mainfrom
Ghraven:fix/streamlit-log-utf8

Conversation

@Ghraven

@Ghraven Ghraven commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • read Streamlit JSONL state logs with explicit UTF-8 encoding
  • add a focused regression test that guards the loader's file-open encoding while preserving non-ASCII state data

Verification

  • python -m pytest tests/integrations/test_streamlit.py -q
  • python -m py_compile burr/integrations/streamlit.py tests/integrations/test_streamlit.py
  • git diff --check

@github-actions github-actions Bot added the area/integrations External integrations (LLMs, frameworks) label Aug 30, 2026

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

The fix is correct and matches the writer, which already opens the file with encoding="utf-8". Problem is the test: it stubs streamlit, graphviz and the hamilton integration but not matplotlib, and burr/integrations/streamlit.py imports matplotlib.colors in the same try block. CI installs .[tests,tracking-client,tracking-server,graphviz] which has no matplotlib, so the test fails with ImportError: Missing plugin streamlit!. I got exactly that locally, and after installing matplotlib it passes (and fails on main, so the test itself is good). Stubbing matplotlib.colors too, or pytest.importorskip("matplotlib"), should fix it.

Smaller things:

  • The module is imported while the deps are stubbed and then stays in sys.modules, so a later test importing it would get the stubbed version. Nothing else imports it today, but monkeypatch.delitem(sys.modules, "burr.integrations.streamlit", raising=False) before the import would keep it clean.
  • Since you're on that line, with open(...) as f: would also close the file handle, it's never closed right now (not from this PR).
  • Just FYI, the default logger writes with json.dumps and ensure_ascii=True, so normal logs are ASCII anyway. This mostly matters for custom json_dump or other tools on Windows. Still a good fix, maybe worth saying in the description.

@Ghraven

Ghraven commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the careful review. I reproduced the missing-matplotlib failure in an isolated Python 3.9 environment. c31b0c2 adds the matplotlib/colors stubs and loads the integration under a temporary module name, so the stubbed module does not remain cached as burr.integrations.streamlit. The reader now closes the log with a context manager, and the test checks that too.

The focused regression passes without installing matplotlib; Black, isort, Flake8, license-header checks and diff checks pass. I have not run the full optional-integration suite. Current head checks show successful labeling/mergeability checks, not a full test run.

Agreed on scope: the UTF-8 fix matters for custom serializers or externally produced non-ASCII logs; the default ensure_ascii=True writer generally produces ASCII.

CI follow-up: the workflow-runs API reports Build Burr and Release Validation as action_required on this head, and documentation as startup_failure. No test jobs have run in those workflows. I have not changed the workflows or rerun them; the full CI result remains unverified.

@CanReader

Copy link
Copy Markdown

Thanks for the quick update. I pulled last commit now and ran it with the same deps CI installs (without matplotlib): the test passes now, and it still fails if I put back main's streamlit.py, so it catches the bug. Loading it under a temp module name is I think a nice way to keep sys.modules clean, and the with open change looks good too.

There's one tiny optional thing you can do: the test uses importlib.util but only does import importlib. It works because something else already loaded importlib.util, but import importlib.util would be safer.

About CI, I think that's just the first time contributor approval, a maintainer needs to approve the runs. Nothing else to do, hope maintainer sees this soon. Good luck!

@Ghraven

Ghraven commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for checking the regression against both versions. I made the explicit importlib.util import in 07de89a and reran the focused Python 3.9 test plus formatting/lint checks successfully. The new head still reports Build Burr/Release Validation as action_required and documentation as startup_failure; I have left those workflows alone.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/integrations External integrations (LLMs, frameworks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants