realm icon indicating copy to clipboard operation
realm copied to clipboard

[bug] UploadTomes() function does not properly deduplicate tome names

Open nullmonk opened this issue 10 months ago • 2 comments

Describe the bug The UploadTomes function uses the path name to check for duplicates instead of the Metadata.Name()

func UploadTomes(ctx context.Context, graph *ent.Client, fileSystem fs.ReadDirFS) error {
	entries, err := fileSystem.ReadDir(".")
	...
	for _, entry := range entries {
		exists, err := graph.Tome.Query().
			Where(tome.Name(entry.Name())). // <-- Using path name not metadata.Name()
			Exist(ctx)
		
		if exists { // <-- Will always be false
			continue
		}
		...
		// Parse metadata
		...
		// Create the tome
		if _, err := graph.Tome.Create().
			SetName(metadata.Name) // <-- Causes "ent: constraint failed: UNIQUE constraint failed: tomes.name"
			...
		}
	}
	return nil
}

To Reproduce Call UploadTomes() twice with the same tomes.

Expected behavior Tome should continue the loop and not error.

nullmonk avatar Jan 15 '26 00:01 nullmonk

I think this is intended refreshing a repo should use the sync button - maybe i'm misunderstanding.

hulto avatar Jan 17 '26 03:01 hulto

There is a "continue if same tome" logic it's just implemented wrong. It doesn't affect tavern bc there is no "refresh buildin times"

I'll research it more

nullmonk avatar Jan 17 '26 04:01 nullmonk