# workspace: Fix edge case when saving workspace with no paths \(\#52810\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/85084b83878d3e9b2542e6b06e3993820de0fde8)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 85084b83878d3e9b2542e6b06e3993820de0fde8

Requested commit: 85084b83878d3e9b2542e6b06e3993820de0fde8

Commit: 85084b83878d3e9b2542e6b06e3993820de0fde8

Tree: 1ca677632f8052f297df395989021fff7d78d460

Author: Eric Huber

Committer: GitHub

## Message

```
workspace: Fix edge case when saving workspace with no paths (#52810)

Closes #48468
Supersedes #52713

Avoid issues with restoring workspaces by making sure to save `paths`
and `paths_order` as `NULL` in the `workspaces` table when there are no
paths. This also helps to avoid losing unsaved buffers in the workspace.

Details:

There was an issue where sporadically, a workspace with no project paths
(and especially with unsaved buffers that could be lost) would not be
restored after restarting Zed. (Refer to #48468 and #15098)

A consistent symptom seemed to be that in the `workspaces` table, the
`paths` and `paths_order` columns might have an empty string instead of
`NULL`. Explicitly saving the workspace with `NULL`s in that case seems
to solve the problem.

Special thanks to @dhnm as his suggested bash script here
https://github.com/zed-industries/zed/issues/48468#issuecomment-3973941351
helped me to realize that the discrepancy with `paths` being an empty
string when it should have been `NULL` was the least common denominator.

Self-Review Checklist:

- [X] I've reviewed my own diff for quality, security, and reliability
- [X] Unsafe blocks (if any) have justifying comments
- [X] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [X] Tests cover the new/changed behavior
- [X] Performance impact has been considered and is acceptable

Release Notes:

- Fix edge case when saving workspace with no paths

No additional tests were added but perhaps someone can suggest one. (The
existing tests seem to be passing for me locally now, unlike the
superseded PR.) The issue seems sporadic based on GitHub issue
discussion, which might make it harder to unit test, although it was
reproducible with a clean install of Zed 0.228.0 on macOS (including a
fresh db).
```

## Parents

- [5294e16547d9cacba49bbc8968183fb70fe8b58b](https://git.cafe/gitcafe/zed/commit/5294e16547d9cacba49bbc8968183fb70fe8b58b?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/85084b83878d3e9b2542e6b06e3993820de0fde8?format=markdown)
