Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AddCategories using provided list as reference (unexpected behaviour) #1162

Open
KondzioSSJ4 opened this issue Feb 9, 2022 · 1 comment
Open
Labels
status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap

Comments

@KondzioSSJ4
Copy link

Issue Summary

AddCategories use provided list as a reference
so any further add's impact on first provided collection

Steps to Reproduce

  1. Create a SendGridMessage
  2. Create a static List with 1 category (or provide it via IOptions<> as normal ppl do)
  3. Add that list to message using AddCategories
  4. Add other category (using AddCategories or AddCategory)
  5. See that list from the static field is bigger
  6. See that list from point 2 is bigger
  7. Send email (success)
  8. Retry steps 1-6
  9. Send email (failed, because there are duplicated category,)

Code Snippet

Your AddCategories looks like:

public void AddCategories(List<string> categories)
        {
            if (Categories == null)
            {
                Categories = new List<string>();
                Categories = categories;
            }
            else
            {
                Categories.AddRange(categories);
            }
        }

but it should be more like:

public void AddCategories(List<string> categories)
        {
            if (Categories == null)
            {
                Categories = new HashSet<string>(categories); // First change type to HashSet to prevent duplications
            }
            else
            {
                foreach (var item in categories) // It need to be like that because this is no longer List but HashSet to prevent duplication
                      Categories.Add(categories);
            }
        }

or at least change to be like:

public void AddCategories(List<string> categories)
        {
            if (Categories == null)
            {
                Categories = categories.ToList();
            }
            else
            {
                 Categories.AddRange(categories);
            }
        }

Technical details:

  • sendgrid-csharp version: 9.25.2.0 (newest)
  • csharp version: .netstandard 2.0
@KondzioSSJ4 KondzioSSJ4 changed the title AddCategories useing provided list as reference (unexpected behaviour) AddCategories using provided list as reference (unexpected behaviour) Feb 9, 2022
@JenniferMah JenniferMah added status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap labels Feb 11, 2022
@JenniferMah
Copy link
Contributor

Hi @KondzioSSJ4! Thanks for bringing this to our attention. This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap
Projects
None yet
Development

No branches or pull requests

2 participants