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

Open Beginner friendly
#1,574 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
85/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
go
Domain
backend

Research direction

The bug is in tavern/tomes/parse.go at line 95 in the UploadTomes function. Replace entry.Name() with metadata.Name in the duplicate existence check so it uses the parsed tome name instead of the filesystem path. Run the tomes package tests to confirm the fix prevents duplicate entries without errors.

Written by the indexing model from the issue text.

Description

bug

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.

Dominant language
Rust
Stars
639
Forks
65
Avg merge
1d 5h
Merged PRs (30d)
62

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from spellshift/realm

All issues in spellshift/realm

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.