Skip to content

Commit 21ead3a

Browse files
authored
PYTHON-3189 Change Stream event document missing to field for rename events (mongodb#924)
1 parent 3e57bde commit 21ead3a

File tree

2 files changed

+317
-7
lines changed

2 files changed

+317
-7
lines changed

test/change_streams/unified/change-streams.json

Lines changed: 315 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"schemaVersion": "1.0",
44
"runOnRequirements": [
55
{
6+
"minServerVersion": "3.6",
67
"topologies": [
78
"replicaset",
89
"sharded-replicaset"
@@ -167,7 +168,6 @@
167168
"description": "Test with document comment - pre 4.4",
168169
"runOnRequirements": [
169170
{
170-
"minServerVersion": "3.6.0",
171171
"maxServerVersion": "4.2.99"
172172
}
173173
],
@@ -211,11 +211,6 @@
211211
},
212212
{
213213
"description": "Test with string comment",
214-
"runOnRequirements": [
215-
{
216-
"minServerVersion": "3.6.0"
217-
}
218-
],
219214
"operations": [
220215
{
221216
"name": "createChangeStream",
@@ -343,7 +338,6 @@
343338
"description": "Test that comment is not set on getMore - pre 4.4",
344339
"runOnRequirements": [
345340
{
346-
"minServerVersion": "3.6.0",
347341
"maxServerVersion": "4.3.99",
348342
"topologies": [
349343
"replicaset"
@@ -426,6 +420,320 @@
426420
]
427421
}
428422
]
423+
},
424+
{
425+
"description": "to field is set in a rename change event",
426+
"runOnRequirements": [
427+
{
428+
"minServerVersion": "4.0.1"
429+
}
430+
],
431+
"operations": [
432+
{
433+
"name": "createChangeStream",
434+
"object": "collection0",
435+
"arguments": {
436+
"pipeline": []
437+
},
438+
"saveResultAsEntity": "changeStream0"
439+
},
440+
{
441+
"name": "dropCollection",
442+
"object": "database0",
443+
"arguments": {
444+
"collection": "collection1"
445+
}
446+
},
447+
{
448+
"name": "rename",
449+
"object": "collection0",
450+
"arguments": {
451+
"to": "collection1"
452+
}
453+
},
454+
{
455+
"name": "iterateUntilDocumentOrError",
456+
"object": "changeStream0",
457+
"expectResult": {
458+
"operationType": "rename",
459+
"ns": {
460+
"db": "database0",
461+
"coll": "collection0"
462+
},
463+
"to": {
464+
"db": "database0",
465+
"coll": "collection1"
466+
}
467+
}
468+
}
469+
]
470+
},
471+
{
472+
"description": "Test unknown operationType MUST NOT err",
473+
"operations": [
474+
{
475+
"name": "createChangeStream",
476+
"object": "collection0",
477+
"arguments": {
478+
"pipeline": [
479+
{
480+
"$project": {
481+
"operationType": "addedInFutureMongoDBVersion",
482+
"ns": 1
483+
}
484+
}
485+
]
486+
},
487+
"saveResultAsEntity": "changeStream0"
488+
},
489+
{
490+
"name": "insertOne",
491+
"object": "collection0",
492+
"arguments": {
493+
"document": {
494+
"_id": 1,
495+
"a": 1
496+
}
497+
}
498+
},
499+
{
500+
"name": "iterateUntilDocumentOrError",
501+
"object": "changeStream0",
502+
"expectResult": {
503+
"operationType": "addedInFutureMongoDBVersion",
504+
"ns": {
505+
"db": "database0",
506+
"coll": "collection0"
507+
}
508+
}
509+
}
510+
]
511+
},
512+
{
513+
"description": "Test newField added in response MUST NOT err",
514+
"operations": [
515+
{
516+
"name": "createChangeStream",
517+
"object": "collection0",
518+
"arguments": {
519+
"pipeline": [
520+
{
521+
"$project": {
522+
"operationType": 1,
523+
"ns": 1,
524+
"newField": "newFieldValue"
525+
}
526+
}
527+
]
528+
},
529+
"saveResultAsEntity": "changeStream0"
530+
},
531+
{
532+
"name": "insertOne",
533+
"object": "collection0",
534+
"arguments": {
535+
"document": {
536+
"_id": 1,
537+
"a": 1
538+
}
539+
}
540+
},
541+
{
542+
"name": "iterateUntilDocumentOrError",
543+
"object": "changeStream0",
544+
"expectResult": {
545+
"operationType": "insert",
546+
"ns": {
547+
"db": "database0",
548+
"coll": "collection0"
549+
},
550+
"newField": "newFieldValue"
551+
}
552+
}
553+
]
554+
},
555+
{
556+
"description": "Test new structure in ns document MUST NOT err",
557+
"runOnRequirements": [
558+
{
559+
"minServerVersion": "3.6",
560+
"maxServerVersion": "5.2"
561+
},
562+
{
563+
"minServerVersion": "6.0"
564+
}
565+
],
566+
"operations": [
567+
{
568+
"name": "createChangeStream",
569+
"object": "collection0",
570+
"arguments": {
571+
"pipeline": [
572+
{
573+
"$project": {
574+
"operationType": "insert",
575+
"ns.viewOn": "db.coll"
576+
}
577+
}
578+
]
579+
},
580+
"saveResultAsEntity": "changeStream0"
581+
},
582+
{
583+
"name": "insertOne",
584+
"object": "collection0",
585+
"arguments": {
586+
"document": {
587+
"_id": 1,
588+
"a": 1
589+
}
590+
}
591+
},
592+
{
593+
"name": "iterateUntilDocumentOrError",
594+
"object": "changeStream0",
595+
"expectResult": {
596+
"operationType": "insert",
597+
"ns": {
598+
"viewOn": "db.coll"
599+
}
600+
}
601+
}
602+
]
603+
},
604+
{
605+
"description": "Test modified structure in ns document MUST NOT err",
606+
"operations": [
607+
{
608+
"name": "createChangeStream",
609+
"object": "collection0",
610+
"arguments": {
611+
"pipeline": [
612+
{
613+
"$project": {
614+
"operationType": "insert",
615+
"ns": {
616+
"db": "$ns.db",
617+
"coll": "$ns.coll",
618+
"viewOn": "db.coll"
619+
}
620+
}
621+
}
622+
]
623+
},
624+
"saveResultAsEntity": "changeStream0"
625+
},
626+
{
627+
"name": "insertOne",
628+
"object": "collection0",
629+
"arguments": {
630+
"document": {
631+
"_id": 1,
632+
"a": 1
633+
}
634+
}
635+
},
636+
{
637+
"name": "iterateUntilDocumentOrError",
638+
"object": "changeStream0",
639+
"expectResult": {
640+
"operationType": "insert",
641+
"ns": {
642+
"db": "database0",
643+
"coll": "collection0",
644+
"viewOn": "db.coll"
645+
}
646+
}
647+
}
648+
]
649+
},
650+
{
651+
"description": "Test server error on projecting out _id",
652+
"runOnRequirements": [
653+
{
654+
"minServerVersion": "4.2"
655+
}
656+
],
657+
"operations": [
658+
{
659+
"name": "createChangeStream",
660+
"object": "collection0",
661+
"arguments": {
662+
"pipeline": [
663+
{
664+
"$project": {
665+
"_id": 0
666+
}
667+
}
668+
]
669+
},
670+
"saveResultAsEntity": "changeStream0"
671+
},
672+
{
673+
"name": "insertOne",
674+
"object": "collection0",
675+
"arguments": {
676+
"document": {
677+
"_id": 1,
678+
"a": 1
679+
}
680+
}
681+
},
682+
{
683+
"name": "iterateUntilDocumentOrError",
684+
"object": "changeStream0",
685+
"expectError": {
686+
"errorCode": 280,
687+
"errorCodeName": "ChangeStreamFatalError",
688+
"errorLabelsContain": [
689+
"NonResumableChangeStreamError"
690+
]
691+
}
692+
}
693+
]
694+
},
695+
{
696+
"description": "Test projection in change stream returns expected fields",
697+
"operations": [
698+
{
699+
"name": "createChangeStream",
700+
"object": "collection0",
701+
"arguments": {
702+
"pipeline": [
703+
{
704+
"$project": {
705+
"optype": "$operationType",
706+
"ns": 1,
707+
"newField": "value"
708+
}
709+
}
710+
]
711+
},
712+
"saveResultAsEntity": "changeStream0"
713+
},
714+
{
715+
"name": "insertOne",
716+
"object": "collection0",
717+
"arguments": {
718+
"document": {
719+
"_id": 1,
720+
"a": 1
721+
}
722+
}
723+
},
724+
{
725+
"name": "iterateUntilDocumentOrError",
726+
"object": "changeStream0",
727+
"expectResult": {
728+
"optype": "insert",
729+
"ns": {
730+
"db": "database0",
731+
"coll": "collection0"
732+
},
733+
"newField": "value"
734+
}
735+
}
736+
]
429737
}
430738
]
431739
}

test/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,5 +1080,7 @@ def prepare_spec_arguments(spec, arguments, opname, entity_map, with_txn_callbac
10801080
arguments["keys"] = list(arguments.pop(arg_name).items())
10811081
elif opname == "drop_index" and arg_name == "name":
10821082
arguments["index_or_name"] = arguments.pop(arg_name)
1083+
elif opname == "rename" and arg_name == "to":
1084+
arguments["new_name"] = arguments.pop(arg_name)
10831085
else:
10841086
arguments[c2s] = arguments.pop(arg_name)

0 commit comments

Comments
 (0)