@@ -333,8 +333,10 @@ func dedupe(query []Subquery) (map[resource]int, error) {
333333 resourceIndices [subquery .res ] = 0
334334 }
335335 for i := 1 ; i < len (query ); i ++ {
336- if query [i ].res == subquery .res {
337- return nil , fmt .Errorf ("duplicate %s operation" , subquery .res )
336+ // If there is only one resource in the query, a list and RUD operation will appear duplicate without the second
337+ // clause
338+ if query [i ].res == subquery .res && ! (subquery .op == list && query [i ].op != list ) {
339+ return nil , fmt .Errorf ("duplicate %s operation (%s and %s)" , subquery .res , query [i ].op , subquery .op )
338340 }
339341 subquery = query [i ]
340342 if subquery .op != list {
@@ -418,8 +420,8 @@ func fillInIDs(root int, query []Subquery) error {
418420 if ! ok && ! c .allowBlankID {
419421 return errors .NotFoundError ("no %s found with key %s" , query [root ].res , query [root ].key )
420422 }
421- if query [root ].id != "" && query [root ].id != id {
422- return fmt .Errorf ("conflicting ids for %s: %s and %s " , query [root ].res , id , query [root ].id )
423+ if id != "" && query [root ].id != "" && query [root ].id != id {
424+ return fmt .Errorf ("conflicting ids for %s: [%s] and [%s] " , query [root ].res , id , query [root ].id )
423425 }
424426 query [root ].id = id
425427 } else {
@@ -448,8 +450,8 @@ func fillInIDs(root int, query []Subquery) error {
448450 if err != nil {
449451 return err
450452 }
451- if query [owner ].id != "" && id != query [owner ].id {
452- return fmt .Errorf ("conflicting ids for %s: %s and %s " , query [owner ].res , id , query [owner ].id )
453+ if id != "" && query [owner ].id != "" && id != query [owner ].id {
454+ return fmt .Errorf ("conflicting ids for %s: (%s) and (%s) " , query [owner ].res , id , query [owner ].id )
453455 }
454456 query [owner ].id = id
455457 }
@@ -742,7 +744,10 @@ type SnapshotResult struct {
742744type resource int
743745
744746func (r resource ) String () string {
745- return resourceNames [r ]
747+ if n , ok := resourceNames [r ]; ok {
748+ return n
749+ }
750+ return "Unknown"
746751}
747752
748753var resourceNames = map [resource ]string {
@@ -769,6 +774,21 @@ const (
769774
770775type operation int
771776
777+ func (o operation ) String () string {
778+ if n , ok := operationNames [o ]; ok {
779+ return n
780+ }
781+ return "Unknown"
782+ }
783+
784+ var operationNames = map [operation ]string {
785+ list : "List" ,
786+ upsert : "Upsert" ,
787+ del : "Delete" ,
788+ read : "Read" ,
789+ inconsistentRead : "Inconsistent Read" ,
790+ }
791+
772792const (
773793 list = operation (iota )
774794 upsert
0 commit comments