fluent-sqlite-driver icon indicating copy to clipboard operation
fluent-sqlite-driver copied to clipboard

Saving multiple records results in duplicate 'id's

Open davidmuzi opened this issue 5 years ago • 2 comments

Bug

Saving multiple records within a loop returns objects with duplicate ids

Expected Result

Records should have unique ids

Steps to reproduce

Using the 'Todo' class from the Vapor template, add:

	func test(_ req: Request) throws -> Future<[Todo]> {
		var todos = [Future<Todo>]()
		for i in 1...5 {
			let todo = Todo(title: "item \(i)")
			todos.append(todo.save(on: req).map {
				print("todo: \($0.id!), title: \($0.title)")
				return $0
			})
		}
		return todos.flatten(on: req)
	}

With the in-memory db, the printout yields:

todo: 2, title: item 1
todo: 3, title: item 2
todo: 4, title: item 3
todo: 5, title: item 4
todo: 5, title: item 5

Notice 2 records have the id 5.

With a sqlite db, the console printout is the same, but, peeking in the sqlite.db itself shows that the records do indeed have unique ids.

"id","title"
1,"item 1"
2,"item 2"
3,"item 3"
4,"item 4"
5,"item 5"

davidmuzi avatar Apr 30 '19 13:04 davidmuzi

This issue does not happen with FluentMySQL nor FluentPosgreSQL

davidmuzi avatar Apr 30 '19 13:04 davidmuzi

Still occurring. Did you find a fix for it?

podratz avatar Aug 16 '19 16:08 podratz

Closing due to extreme age

gwynne avatar Oct 19 '23 14:10 gwynne