Skip to content

Fix for showing on GET and persisting Tags on SET (if not given) for Database, Server and Elastic Pool #3206

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

Merged
merged 7 commits into from
Nov 30, 2016

Conversation

vaishali33
Copy link
Contributor

@vaishali33 vaishali33 commented Nov 17, 2016

Description

Fix for showing on GET and persisting Tags on SET (if not given) for Database, Server and Elastic Pool.
Also fixed Set-AzureRmSqlServer if SqlAdministratorPassword is not provided.

Fixes #1134 :Fetching Tags from Get-AzureRmSqlDatabase to set Tags values in set-AzureRmSqlDatabase if not provided


This checklist is used to make sure that common guidelines for a pull request are followed. You can find a more complete discussion of PowerShell cmdlet best practices here.

General Guidelines

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.
  • The pull request does not introduce breaking changes (unless a major version change occurs in the assembly and module).

Testing Guidelines

  • Pull request includes test coverage for the included changes.
  • PowerShell scripts used in tests should do any necessary setup as part of the test or suite setup, and should not use hard-coded values for locations or existing resources.

Cmdlet Signature Guidelines

  • New cmdlets that make changes or have side effects should implement ShouldProcess and have SupportShouldProcess=true specified in the cmdlet attribute. You can find more information on ShouldProcess here.
  • Cmdlet specifies OutputType attribute if any output is produced - if the cmdlet produces no output, it should implement a PassThrough parameter.

Cmdlet Parameter Guidelines

  • Parameter types should not expose types from the management library - complex parameter types should be defined in the module.
  • Complex parameter types are discouraged - a parameter type should be simple types as often as possible. If complex types are used, they should be shallow and easily creatable from a constructor or another cmdlet.
  • Cmdlet parameter sets should be mutually exclusive - each parameter set must have at least one mandatory parameter not in other parameter sets.

@azurecla
Copy link

Hi @vaishali33, I'm your friendly neighborhood Azure Pull Request Bot (You can call me AZPRBOT). Thanks for your contribution!


It looks like you're working at Microsoft (vanark). If you're full-time, we DON'T require a contribution license agreement.



If you are a vendor, DO please sign the electronic contribution license agreement. It will take 2 minutes and there's no faxing! https://cla.azure.com.

TTYL, AZPRBOT;

@azuresdkci
Copy link

Can one of the admins verify this patch?

@@ -113,7 +113,7 @@ protected override IEnumerable<AzureSqlDatabaseModel> ApplyUserInputToModel(IEnu
Edition = Edition,
MaxSizeBytes = MaxSizeBytes,
RequestedServiceObjectiveName = RequestedServiceObjectiveName,
Tags = TagsConversionHelper.CreateTagDictionary(Tags, validate: true),
Tags = this.MyInvocation.BoundParameters.ContainsKey("Tags") ? TagsConversionHelper.CreateTagDictionary(Tags, validate: true) : model.FirstOrDefault().Tags,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If .FirstOrDefault returns null, .Tags will throw NullRefException. I think that model should always have exactly one element here, if this is correct then use Single instead of FirstOrDefault

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this line is a little complicated and is repeated several times, I suggest extracting it as a common method

Copy link
Contributor Author

@vaishali33 vaishali33 Nov 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that we are using .FirstOrDefault in code just two lines below model.FirstOrDefault().Location. model.FirstOrDefault() should not be null or else we will not reach to this point in code.

For second comment I don't think this its complex statement and its only used at 3 places. Doesn't make sense to extract that to a method in some base class.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you know that the collection is non-empty, then using FirstOrDefault() is just confusing to the reader - use First() instead.

The exact same code in 3 places is enough justification to extract method. It can be in utility class or base class, your choice. The fact that the code is complex enough to have a bug once (this time) means that it's complex enough to have a bug again, and when that happens the fix should only be done in one place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments addressed.

@hovsepm
Copy link
Contributor

hovsepm commented Nov 18, 2016

@azuresdkci test this please

@hovsepm
Copy link
Contributor

hovsepm commented Nov 18, 2016

@azuresdkci add to whitelist.

Copy link
Member

@markcowl markcowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please respond to jaredmoo review comments and please add a test to cover this scenario - it can be a unit test or a scenario test

@@ -95,12 +95,13 @@ protected override IEnumerable<Model.AzureSqlServerModel> ApplyUserInputToModel(
{
// Construct a new entity so we only send the relevant data to the server
List<Model.AzureSqlServerModel> updateData = new List<Model.AzureSqlServerModel>();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove extra line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@markcowl
Copy link
Member

@vaishali33 Please respond to review comments, please read and fill out the checklist.

@markcowl markcowl removed this from the December 2016 milestone Nov 22, 2016
@shahabhijeet
Copy link
Contributor

@vaishali33 please address the PR. Code complete is next week.

@vaishali33
Copy link
Contributor Author

@markcowl and @shahabhijeet I have addressed the comments and added tests. Please review. Thank you!

Vaishali Narkhede added 3 commits November 29, 2016 12:03
@jaredmoo
Copy link
Contributor

Thanks for the changes Vaishali, LGTM!

@shahabhijeet shahabhijeet merged commit 3d906ff into Azure:dev Nov 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants