marimo icon indicating copy to clipboard operation
marimo copied to clipboard

Switching from columns view to another view loses column metadata

Open akshayka opened this issue 1 year ago • 20 comments

Describe the bug

  • Create a notebook with a two columns, and arrange cells across the columns
  • Switch to a compact view and save.

Expected behavior:

  • Column metadata is still persisted in the notebook file.

Actual behavior:

  • Column metadata is erased from the file.

Environment

{
  "marimo": "0.10.16",
  "OS": "Darwin",
  "OS Version": "22.5.0",
  "Processor": "arm",
  "Python Version": "3.12.4",
  "Binaries": {
    "Browser": "131.0.6778.265",
    "Node": "v21.5.0"
  },
  "Dependencies": {
    "click": "8.1.8",
    "docutils": "0.21.2",
    "itsdangerous": "2.2.0",
    "jedi": "0.19.2",
    "markdown": "3.7",
    "narwhals": "1.23.0",
    "packaging": "24.2",
    "psutil": "6.1.1",
    "pygments": "2.19.1",
    "pymdown-extensions": "10.14.1",
    "pyyaml": "6.0.2",
    "ruff": "0.9.2",
    "starlette": "0.45.2",
    "tomlkit": "0.13.2",
    "typing-extensions": "4.12.2",
    "uvicorn": "0.34.0",
    "websockets": "14.2"
  },
  "Optional Dependencies": {}
}

Code to reproduce

import marimo

__generated_with = "0.10.16"
app = marimo.App(width="columns")


@app.cell(column=0)
def _():
    "1"
    return


@app.cell(column=1)
def _():
    "2"
    return


if __name__ == "__main__":
    app.run()

akshayka avatar Jan 23 '25 01:01 akshayka

Hi I would like to work on this but I'm unable to recreate the issue. I wasn't able to figure out how to create a notebook with columns instead of vertical rows.

BhavanaK223 avatar Feb 17 '25 21:02 BhavanaK223

@BhavanaK223 - glad to hear you want to work on this! here are the docs: https://docs.marimo.io/guides/editor_features/overview/#editor-widths

The toggle is in the top-right settings menu. Changing the "width" to columns

mscolnick avatar Feb 17 '25 21:02 mscolnick

Hi @mscolnick, I was able to switch to columns and replicate the steps but the metadata isn't lost when I switch to compact after running. Any cells made/ created revert to the same column when switched into compact mode.

BhavanaK223 avatar Feb 17 '25 22:02 BhavanaK223

Can you try saving and see if the metadata is lost?

mscolnick avatar Feb 17 '25 22:02 mscolnick

Yep, I tried saving before I switched to the compact width, and the data was still saved. I tried again saving after switching to compact mode and it had the same result

BhavanaK223 avatar Feb 17 '25 23:02 BhavanaK223

I think after you switch to "compact", then save, then look at the file, you'll see the column config missing.

mscolnick avatar Feb 18 '25 00:02 mscolnick

to clarify, the intended behavior is that @app.cell(column=1) is still part of the meta data in the saved file, even if saved in compact layout again?

jo-soft avatar Jun 13 '25 09:06 jo-soft

@jo-soft yep exactly

mscolnick avatar Jun 14 '25 02:06 mscolnick

I was able to reproduce this bug and it looks like a good first issue. I have been using marimo for awhile and looking to support/contribute.

$ diff copy_repro.mo.py orig_repro.mo.py
4c4
< app = marimo.App()
---
> app = marimo.App(width="columns")
7c7
< @app.cell
---
> @app.cell(column=0)
13c13
< @app.cell
---
> @app.cell(column=1)

let me know if you'd still like help on this issue

mwynn1 avatar Oct 05 '25 23:10 mwynn1

hey @mwynn1, its still open and unclaimed at the moment, feel free to take it! happy to support you as needed

mscolnick avatar Oct 06 '25 01:10 mscolnick

thanks @mscolnick sgtm!

just to clarify we should be retaining @app.cell(column=<index>) if we toggle width from columns to any of the other 3 width choices (not just compact)?

mwynn1 avatar Oct 06 '25 02:10 mwynn1

yep correct

mscolnick avatar Oct 06 '25 02:10 mscolnick

@mscolnick I have a feature branch with a proposed fix -- is marimo following a fork and pull model for contributors? I could not push/make PR

mwynn1 avatar Oct 09 '25 05:10 mwynn1

@mwynn1 can you link tot his repo?

dmadisetti avatar Oct 09 '25 20:10 dmadisetti

@mwynn1 can you link tot his repo?

I figured it out. thanks!

mwynn1 avatar Oct 13 '25 03:10 mwynn1

Re: this issue I have draft PR up -- adding some tests now.

I noticed another issue with columns that seems unrelated to the metadata issue in this ticket:

If you change to column width in edit mode you get/see columns. If you toggle to app view, no cols are displayed (just vertical cells). If you refresh the browser, the columns will display in app view and will continue to do so going forward. Seems like something is not getting set when rendering the app view with columns. happy to make an issue for this. I didn't see a quick fix for it but there may be something obvious I missed

mwynn1 avatar Oct 13 '25 04:10 mwynn1

@mwynn1, thanks for finding that additional issue. Filing it on GH would be great. I'm not sure how much the "columns" view is used in app mode (I also thought it wasn't supported), but if we have an issue for it, it can help track / up-vote if people want it supported.

mscolnick avatar Oct 13 '25 13:10 mscolnick

I’d like to take this on, if maintainers are still comfortable with the fix.

I reproduced the current behavior on main at df8dbed0. When the width leaves columns, EditApp dispatches mergeAllColumns; the document-change mapper then emits set-config changes with column: 0 for the former later columns. The regular save path also derives configs from the now-single-column tree, so this needs to preserve metadata across both the transaction and explicit-save boundaries (not just change the rendering).

I confirmed that both earlier attempts, #6752 and #10461, are closed and that there is currently no open PR. My proposed scope is a focused owner-boundary fix plus a regression that proves the persisted column configs survive the width-driven merge while the rendered cell order is still flattened. I’ll also include before/after UI evidence.

Would you be comfortable assigning this to me / marking it ready?

Adkid-Zephyr avatar Aug 19 '26 10:08 Adkid-Zephyr

Hi @mscolnick — just following up now that about a week has passed. I’m still happy to implement the focused fix and regression coverage described above, and I’ll continue to wait for maintainer confirmation before starting. If the team would prefer not to pursue this issue or considers it covered elsewhere, no problem — please let me know and I’ll step back.

Adkid-Zephyr avatar Aug 27 '26 08:08 Adkid-Zephyr

Hi @akshayka, I'd like to work on this one. I've traced the root cause: it's in the frontend, not codegen getCellConfigs() in frontend/src/core/cells/cells.ts force-overwrites column to null in its single-column branch whenever the notebook isn't currently in multi-column view, even though the value is still intact in cell config at that point (nothing upstream, e.g. mergeAllColumns, actually clears it). The backend round-trip is faithful, so this is a one-line fix plus regression tests in utils.test.ts.

I'll open a PR shortly.

Sushit-prog avatar Sep 11 '26 03:09 Sushit-prog