moto icon indicating copy to clipboard operation
moto copied to clipboard

Fifo messages aren't deduped

Open anderson-dan-w opened this issue 7 years ago • 3 comments

Anaconda-IPython sys.version[:5] == '2.7.6' boto3.__version__ == '1.5.17' moto.__version__ == (u'1.2.0',)

Reproduce

import boto3
from moto import mock_sqs

@mock_sqs
def dedupe_fifo():
    sqs = boto3.resource('sqs', region_name='us-west-2')
    queue = sqs.create_queue(
        QueueName='my-queue.fifo',
        Attributes={
            'FifoQueue': 'true',
        },
    )

    for _ in range(5):
        queue.send_message(
            MessageBody="test",
            MessageDeduplicationId="1",
            MessageGroupId="2",
        )
    assert queue.attributes['ApproximateNumberOfMessages'] == 1

Expected Behavior

For the assert to pass, as messages have been deduped. Note that my code sample should work whether Content-based deduplication is enabled or not, since the MessageBody is identical

Experienced Behavior

No de-duping occurs, so I get an AssertionError, assert 5 == 1, where 5 is length of my for-loop

anderson-dan-w avatar Jan 18 '18 21:01 anderson-dan-w

Possibly related, when I retrieve messages from a mocked FIFO queue, the MessageGroupId is not present.

DHager avatar Apr 18 '18 21:04 DHager

Thanks for opening. Marking this as a feature request.

spulec avatar May 31 '18 03:05 spulec

Also encountered this so just wanted to +1

dstockstad avatar Jul 10 '18 10:07 dstockstad

@bblommers let me take a look at this

rafcio19 avatar Apr 05 '23 14:04 rafcio19

nvm, looks like it's already been tackled https://github.com/getmoto/moto/blob/master/moto/sqs/models.py#L533

rafcio19 avatar Apr 05 '23 14:04 rafcio19

@rafcio19 I'd have to verify this against AWS, but from my understanding of the docs and our implementation, two scenarios are not yet implemented in Moto:

  • with ContentBasedDeduplication can be set to False (like in the example above) - we should still deduplicate. (The if-statement you linked is only active if ContentBasedDeduplication is set to True)
  • the deduplication_id-attribute is set when ContentBasedDeduplication=True (https://github.com/getmoto/moto/pull/3538/files) - I assume that it only needs to be set if it isn't explicitly provided by the user

bblommers avatar Apr 05 '23 16:04 bblommers

Gotcha, in that case let me take a look 👀

rafcio19 avatar Apr 06 '23 06:04 rafcio19