juicedata/juicefs · error · RuntimeError

Can only commit if not already set to autocommit

Error message

Can only commit if not already set to autocommit

What it means

LocalFile.commit() finalizes a write by renaming the temp file to its final path. If autocommit is enabled (default), the write was already committed, so calling commit() raises RuntimeError('Can only commit if not already set to autocommit').

Source

Thrown at sdk/python/juicefs/juicefs/spec.py:261

        self.__dict__.update(state)
        if "r" in state["mode"]:
            self.f = None
            self._open()
            self.f.seek(loc)

    def __getstate__(self):
        d = self.__dict__.copy()
        d.pop("f")
        if "r" in self.mode:
            d["loc"] = self.f.tell()
        else:
            if not self.f.closed:
                raise ValueError("Cannot serialise open write-mode local file")
        return d

    def commit(self):
        if self.autocommit:
            raise RuntimeError("Can only commit if not already set to autocommit")
        self.fs.fs.rename(self.temp, self.path)

    def discard(self):
        if self.autocommit:
            raise RuntimeError("Can only commit if not already set to autocommit")
        self.fs.fs.remove(self.temp)

    def tell(self):
        return self.f.tell()

    def seek(self, loc, whence=0):
        return self.f.seek(loc, whence)

    def write(self, data):
        return self.f.write(data)

    def read(self, length=-1):
        return self.f.read(length)

View on GitHub (pinned to c9a67b23e8)

Solutions

  1. Open with autocommit=False: fs.open(path, 'wb', autocommit=False) before calling commit()
  2. Check f.autocommit and skip commit() when it is True
  3. Rely on close() to finalize when using the default autocommit behavior

Example fix

// before
f = fs.open('/mnt/jfs/out', 'wb')
f.write(b'data')
f.commit()  # RuntimeError
// after
f = fs.open('/mnt/jfs/out', 'wb', autocommit=False)
f.write(b'data')
f.commit()
Defensive patterns

Strategy: validation

Validate before calling

if not f.autocommit:
    f.commit()

Try / catch

try:
    f.commit()
except RuntimeError as e:
    if 'autocommit' in str(e):
        pass  # already committed

Prevention

When it happens

Trigger: Calling f.commit() on a file opened with default autocommit=True; double-committing after a prior explicit commit; framework code that auto-commits on close then user code commits again.

Common situations: Explicit transaction-style code copied from fsspec examples without disabling autocommit; combining commit() with a with-block that auto-commits; migrating from manual-commit backends like s3fs to JuiceFS local files.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of juicedata/juicefs@c9a67b23e8 (2026-09-06). Data as JSON: /api/errors/e1fb7d9c907cafc3. Report an issue: GitHub.