Skip to content

Commit

Permalink
[data-tables] Avoid mutating client options parameter (#27061)
Browse files Browse the repository at this point in the history
### Packages impacted by this PR

`@azure/data-tables`

### Describe the problem that is addressed by this PR

If a consumer re-uses a single options argument when configuring
multiple clients, they may run into issues because both the TableClient
and TableServiceClient mutate the options bag directly instead of
creating a copy.

### Provide a list of related PRs _(if any)_

This issue was originally raised in the following community PR, but it
was never merged:

#26211
  • Loading branch information
xirzec authored Sep 8, 2023
1 parent c1c67fa commit 337b850
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
5 changes: 3 additions & 2 deletions sdk/tables/data-tables/src/TableClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
InternalClientPipelineOptions,
OperationOptions,
ServiceClient,
ServiceClientOptions,
} from "@azure/core-client";
import { GeneratedClient, TableDeleteEntityOptionalParams } from "./generated";
import {
Expand Down Expand Up @@ -232,10 +233,10 @@ export class TableClient {
this.clientOptions = (!isCredential(credentialOrOptions) ? credentialOrOptions : options) || {};

this.allowInsecureConnection = this.clientOptions.allowInsecureConnection ?? false;
this.clientOptions.endpoint = this.clientOptions.endpoint || this.url;

const internalPipelineOptions: InternalClientPipelineOptions = {
const internalPipelineOptions: ServiceClientOptions & InternalClientPipelineOptions = {
...this.clientOptions,
endpoint: this.clientOptions.endpoint || this.url,
loggingOptions: {
logger: logger.info,
additionalAllowedHeaderNames: [...TablesLoggingAllowedHeaderNames],
Expand Down
31 changes: 16 additions & 15 deletions sdk/tables/data-tables/src/TableServiceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import {
SetPropertiesOptions,
SetPropertiesResponse,
} from "./generatedModels";
import { InternalClientPipelineOptions, OperationOptions } from "@azure/core-client";
import {
InternalClientPipelineOptions,
OperationOptions,
ServiceClientOptions,
} from "@azure/core-client";
import {
ListTableItemsOptions,
TableItem,
Expand Down Expand Up @@ -161,21 +165,18 @@ export class TableServiceClient {
const clientOptions =
(!isCredential(credentialOrOptions) ? credentialOrOptions : options) || {};

clientOptions.endpoint = clientOptions.endpoint || this.url;

const internalPipelineOptions: InternalClientPipelineOptions = {
const internalPipelineOptions: ServiceClientOptions & InternalClientPipelineOptions = {
...clientOptions,
...{
loggingOptions: {
logger: logger.info,
additionalAllowedHeaderNames: [...TablesLoggingAllowedHeaderNames],
},
deserializationOptions: {
parseXML,
},
serializationOptions: {
stringifyXML,
},
endpoint: clientOptions.endpoint || this.url,
loggingOptions: {
logger: logger.info,
additionalAllowedHeaderNames: [...TablesLoggingAllowedHeaderNames],
},
deserializationOptions: {
parseXML,
},
serializationOptions: {
stringifyXML,
},
};
const client = new GeneratedClient(this.url, internalPipelineOptions);
Expand Down

0 comments on commit 337b850

Please sign in to comment.