spacedriveapp/spacedrive · error

Entry not found after creation

Error message

Entry not found after creation

What it means

DatabaseStorage::create_entry returned an entry_id, but the immediate find_by_id for that same id finds no row. Since the insert succeeded on self.db, the miss implies the insert was rolled back, the row was deleted within milliseconds, or self.db points at a different connection/transaction than the one that wrote. It is a self-inconsistency check after creation.

Source

Thrown at core/src/ops/indexing/change_detection/persistent.rs:255

		}

		let entry_id = DatabaseStorage::create_entry(
			&mut state,
			&self.db,
			library.as_deref(),
			metadata,
			self.volume_id,
			parent_path,
		)
		.await
		.map_err(|e| anyhow::anyhow!("Failed to create entry: {}", e))?;

		self.entry_id_cache.insert(metadata.path.clone(), entry_id);

		let entry = entities::entry::Entity::find_by_id(entry_id)
			.one(&self.db)
			.await?
			.ok_or_else(|| anyhow::anyhow!("Entry not found after creation"))?;

		Ok(EntryRef {
			id: entry.id,
			uuid: entry.uuid,
			path: metadata.path.clone(),
			kind: metadata.kind,
		})
	}

	async fn update(&mut self, entry: &EntryRef, metadata: &DirEntry) -> Result<()> {
		use crate::ops::indexing::database_storage::DatabaseStorage;

		DatabaseStorage::update_entry(&self.db, entry.id, metadata)
			.await
			.map_err(|e| anyhow::anyhow!("Failed to update entry: {}", e))?;

		Ok(())
	}

View on GitHub (pinned to 6dfeccf211)

Solutions

  1. Have DatabaseStorage::create_entry return the created row (or construct EntryRef directly from the insert) instead of re-querying
  2. Check whether a concurrent delete/reindex job is running on the same library
  3. Verify all queries in this adapter use the same connection (self.db) as the insert
Defensive patterns

Strategy: try-catch

Try / catch

let entry = match entities::entry::Entity::find_by_id(entry_id).one(&self.db).await? {
    Some(e) => e,
    None => {
        tracing::warn!(%entry_id, "entry vanished immediately after creation; retrying once");
        return Err(anyhow::anyhow!("Entry not found after creation"));
    }
};

Prevention

When it happens

Trigger: Concurrent delete of the just-created entry; the create ran inside a transaction that aborted after returning the id; connection pooling routing the follow-up SELECT to a replica or a different DB file.

Common situations: Duplicate watcher events where one worker creates and another deletes immediately; SQLite WAL setups with a stale read connection; nested transaction rollback paths.

Related errors


AI-assisted analysis of spacedriveapp/spacedrive@6dfeccf211 (2026-08-16). Data as JSON: /api/errors/36b2b7a33fe2a908. Report an issue: GitHub.