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

Fix table entities error checking #563

Merged
merged 1 commit into from
Mar 2, 2017
Merged

Fix table entities error checking #563

merged 1 commit into from
Mar 2, 2017

Conversation

johnglover
Copy link
Contributor

There is a nasty bug in the current TableService code that results in some errors being silently dropped.

The following functions are only checking the response code if a call to c.execTable returns an error:

  • InsertEntity
  • UpdateEntity
  • InsertOrReplaceEntity
  • InsertOrMergeEntity

In some cases calls to c.execTable can fail without returning errors. In particular, it calls client.execInternalJSON, which does return an error for bad status codes with no response body (https://github.com/Azure/azure-sdk-for-go/blob/master/storage/client.go#L414). However if there is some response body, it then unmarshals it, and only returns an error if this unmarshalling fails (https://github.com/Azure/azure-sdk-for-go/blob/master/storage/client.go#L420).

It is unclear if this behaviour (for execInternalJSON) is intentional or not, so this PR just makes sure that the response code is checked at all times. It also adds a new test verifying that trying to insert entities into nonexistent tables should fail as expected.

Some functions were only checking the response
code if a call to execTable returned an error,
but in some cases calls to this can fail
without returning errors. It is unclear if this
behaviour is intentiona or not, so for now we
just check the response code at all times.
@msftclas
Copy link

msftclas commented Mar 2, 2017

@johnglover,
Thanks for your contribution.
To ensure that the project team has proper rights to use your work, please complete the Contribution License Agreement at https://cla.microsoft.com.

It will cover your contributions to all Microsoft-managed open source projects.
Thanks,
Microsoft Pull Request Bot

@msftclas
Copy link

msftclas commented Mar 2, 2017

@johnglover, thanks for signing the contribution license agreement. We will now validate the agreement and then the pull request.

Thanks, Microsoft Pull Request Bot

Copy link
Member

@marstr marstr left a comment

Choose a reason for hiding this comment

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

Nice catch. I would have hoped that code review would have caught this before the offending lines were ever committed.

We've moved the storage package into its own repository, and are primarily doing development there. Furthermore, in general we like to take pull-requests to the dev branch. However, given the nature of this bug, I'd like to get it in as a release patch ASAP. For that reason, I believe the best course of action is to accept this PR and cherry-pick this change into the new storage repository. Thoughts, @mcardosos and @jhendrixMSFT?


tn := AzureTable(randTable())

ce := &CustomEntity{Name: "Luke", Surname: "Skywalker", Number: 1543, PKey: "pkey", RKey: "5"}
Copy link
Member

Choose a reason for hiding this comment

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

^ Very nice name choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Taken from an existing test case so I can't take credit :)

}

// MergeEntity merges the contents of an entity with the
// one passed as parameter.
// The function fails if there is no entity
// with the same PartitionKey and RowKey in the table.
func (c *TableServiceClient) MergeEntity(table AzureTable, entity TableEntity) error {
if sc, err := c.execTable(table, entity, true, "MERGE"); err != nil {
return checkRespCode(sc, []int{http.StatusNoContent})
sc, err := c.execTable(table, entity, true, "MERGE")
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to pull "MERGE" out as a const. However, I suspect that this isn't the right package to host its definition. I'll file an issue to track this follow up item.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would like the http package to include it as a const 😢

@mcardosos
Copy link
Contributor

Sure, I agree with merging here and then cherry-pick.

@mcardosos
Copy link
Contributor

BTW, the repo for storage is now https://github.com/Azure/azure-storage-go :)

@mcardosos mcardosos merged commit 4897648 into Azure:master Mar 2, 2017
@johnglover
Copy link
Contributor Author

@mcardosos: thanks, I wasn't aware of the separate storage repo.

@mcardosos
Copy link
Contributor

Fixed in the other repo too!

marstr pushed a commit to marstr/azure-sdk-for-go that referenced this pull request Apr 27, 2017
marstr pushed a commit that referenced this pull request Apr 28, 2017
mcardosos added a commit that referenced this pull request May 4, 2017
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.

4 participants