Ticket #331 (closed defect: invalid)
Struct creation failure leaves orphan document in collection
|Reported by:||anonymous||Owned by:||jaymccarthy|
Consider following code and test case which is defined on a collection with a unique index constraint on global-unique-user-id. The code is designed to test that creation of a second user with same id will fail. The failure does occur, but the second record continues to exist with only the _id field present in it. This does not happen when I try the same test directly in mongo shell.
(define-mongo-struct user "users"
[user-profile-data #:set-add #:push]
[profiles #:set-add #:push]
[default-profile #:set-add #:push]
[app-specific-profiles #:set-add #:push]))
"Unique id creation"
(and (mongo-dict? x)
(not (bson-null? (mongo-dict-ref x 'global-unique-user-id))))))
(and (equal? (authentication-handle-global-unique-user-id auth-handle) "0000")
(equal? (authentication-handle-auth-handle-type auth-handle) "pxSAN")
(equal? (authentication-handle-auth-handle auth-handle) "me")
(equal? (authentication-handle-auth-credentials auth-handle) "pwd"))))
(let ((user (make-user #:global-unique-user-id "0000")))
(check-pred user? user "User 0000 Created")
(check-equal? (user-global-unique-user-id user) "0000")
(check-exn exn:fail? (make-user #:global-unique-user-id "0000"))
(mongo-collection-remove! (mongo-collection (current-mongo-db) "users") '((global-unique-user-id . 1)))))