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

Do not terminate listing for token-based pagination resources on empty response #530

Merged
merged 6 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions .codegen/service.py.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -270,29 +270,32 @@ class {{.Name}}API:{{if .Description}}
{{- end}}
while True:
json = {{template "method-do" .}}
if '{{.Pagination.Results.Name}}' not in json or not json['{{.Pagination.Results.Name}}']:
if '{{.Pagination.Results.Name}}' in json:
for v in json['{{.Pagination.Results.Name}}']:
{{if .NeedsOffsetDedupe -}}
i = v['{{.IdentifierField.Name}}']
if i in seen:
continue
seen.add(i)
{{end -}}
yield {{.Pagination.Entity.PascalName}}.from_dict(v)
{{ if .Pagination.Token -}}
if '{{.Pagination.Token.Bind.Name}}' not in json or not json['{{.Pagination.Token.Bind.Name}}']:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is slightly reordered but designed to match the Go SDK pagination logic exactly.

return
for v in json['{{.Pagination.Results.Name}}']:
{{if .NeedsOffsetDedupe -}}
i = v['{{.IdentifierField.Name}}']
if i in seen:
continue
seen.add(i)
{{end -}}
yield {{.Pagination.Entity.PascalName}}.from_dict(v)
{{if eq .Path "/api/2.0/clusters/events" -}}
{{if eq "GET" .Verb}}query{{else}}body{{end}}['{{.Pagination.Token.PollField.Name}}'] = json['{{.Pagination.Token.Bind.Name}}']
{{- else if eq .Path "/api/2.0/clusters/events" -}}
if 'next_page' not in json or not json['next_page']:
return
body = json['next_page']
{{- else if .Pagination.Token -}}
if '{{.Pagination.Token.Bind.Name}}' not in json or not json['{{.Pagination.Token.Bind.Name}}']:
{{- else -}}
if '{{.Pagination.Results.Name}}' not in json or not json['{{.Pagination.Results.Name}}']:
return
{{if eq "GET" .Verb}}query{{else}}body{{end}}['{{.Pagination.Token.PollField.Name}}'] = json['{{.Pagination.Token.Bind.Name}}']
{{- else if eq .Pagination.Increment 1 -}}
{{ if eq .Pagination.Increment 1 -}}
query['{{.Pagination.Offset.Name}}'] += 1
{{- else -}}
query['{{.Pagination.Offset.Name}}'] += len(json['{{.Pagination.Results.Name}}'])
{{- end}}
{{- end}}
{{else -}}
json = {{template "method-do" .}}
parsed = {{.Response.PascalName}}.from_dict(json).{{template "safe-snake-name" .Pagination.Results}}
Expand Down
56 changes: 24 additions & 32 deletions databricks/sdk/service/catalog.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions databricks/sdk/service/compute.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 42 additions & 36 deletions databricks/sdk/service/iam.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions databricks/sdk/service/jobs.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading