Skip to content

Commit

Permalink
fix: add warning about python sdk login_user breaking change in 21.4.0 (
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldodge79 authored Apr 13, 2021
1 parent aea0424 commit c74d447
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
15 changes: 15 additions & 0 deletions packages/sdk-codegen/src/python.gen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ DelimSequence = model.DelimSequence
# NOTE: Do not edit this file generated by Looker SDK Codegen
import datetime
from typing import Any, MutableMapping, Optional, Sequence, Union
import warnings
from . import models
from looker_sdk.rtl import api_methods
Expand Down Expand Up @@ -409,6 +410,20 @@ return response`
transport_options=transport_options
)
assert isinstance(response, list)
return response`
const actual = gen.httpCall(indent, method)
expect(actual).toEqual(expected)
})
it('assert login_user has a warning', () => {
const method = apiTestModel.methods.login_user
const expected = `warnings.warn("login_user behavior changed significantly in 21.4.0. See https://git.io/JOtH1")
response = self.post(
f"/login/{user_id}",
models.AccessToken,
query_params={"associative": associative},
transport_options=transport_options
)
assert isinstance(response, models.AccessToken)
return response`
const actual = gen.httpCall(indent, method)
expect(actual).toEqual(expected)
Expand Down
12 changes: 9 additions & 3 deletions packages/sdk-codegen/src/python.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export class PythonGen extends CodeGen {
# ${this.warnEditing()}
import datetime
from typing import Any, MutableMapping, Optional, Sequence, Union
import warnings
from . import models
from ${this.packagePath}.rtl import api_methods
Expand Down Expand Up @@ -401,15 +402,20 @@ ${this.hooks.join('\n')}
}
result = this.argFill(result, returnType)
result = this.argFill(result, `f"${method.endpoint}"`)
return result
return this.bumper(indent) + result
}

httpCall(indent: string, method: IMethod) {
const bump = indent + this.indentStr
const args = this.httpArgs(bump, method)
const methodCall = `${indent}response = ${this.it(
let methodCall = `${indent}response = ${this.it(
method.httpMethod.toLowerCase()
)}`
if (method.name === 'login_user') {
methodCall =
`${indent}warnings.warn("login_user behavior changed significantly ` +
`in 21.4.0. See https://git.io/JOtH1")\n${methodCall}`
}
let assertTypeName = this.methodReturnType(method)
switch (method.type.className) {
case 'ArrayType':
Expand All @@ -432,7 +438,7 @@ ${this.hooks.join('\n')}
const returnStmt = `${indent}return response`
return (
`${methodCall}(\n` +
`${bump.repeat(3)}${args}\n` +
`${this.bumper(indent)}${args}\n` +
`${indent})\n` +
`${assertion}\n` +
`${returnStmt}`
Expand Down
4 changes: 4 additions & 0 deletions python/looker_sdk/sdk/api31/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# NOTE: Do not edit this file generated by Looker SDK Codegen for Looker 21.4 API 3.1
import datetime
from typing import Any, MutableMapping, Optional, Sequence, Union
import warnings

from . import models
from looker_sdk.rtl import api_methods
Expand Down Expand Up @@ -111,6 +112,9 @@ def login_user(
transport_options: Optional[transport.TransportOptions] = None,
) -> models.AccessToken:
"""Login user"""
warnings.warn(
"login_user behavior changed significantly in 21.4.0. See https://git.io/JOtH1"
)
response = self.post(
f"/login/{user_id}",
models.AccessToken,
Expand Down
4 changes: 4 additions & 0 deletions python/looker_sdk/sdk/api40/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# NOTE: Do not edit this file generated by Looker SDK Codegen for Looker 21.4 API 4.0
import datetime
from typing import Any, MutableMapping, Optional, Sequence, Union
import warnings

from . import models
from looker_sdk.rtl import api_methods
Expand Down Expand Up @@ -111,6 +112,9 @@ def login_user(
transport_options: Optional[transport.TransportOptions] = None,
) -> models.AccessToken:
"""Login user"""
warnings.warn(
"login_user behavior changed significantly in 21.4.0. See https://git.io/JOtH1"
)
response = self.post(
f"/login/{user_id}",
models.AccessToken,
Expand Down
1 change: 1 addition & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
},
"python": {
"release-type": "python",
"release-as": "21.4.1",
"draft": true,
"package-name": "looker_sdk"
}
Expand Down

0 comments on commit c74d447

Please sign in to comment.