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

Added strict runtime type validation for all @dataclass'es and method arguments #264

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nfx
Copy link
Contributor

@nfx nfx commented Aug 4, 2023

This PR adds strict type validation for all types while performing request serialization: @dataclass'es, enums, ints, strs, maps, booleans.

image

Benefits:

  • this gives a clear error message about the expected type name in case of a developer error.
  • this makes overall validation easier.

Downsides:

  • this makes sloppy coding harder, as novice developers would have to specify explicit @dataclass types instead of using dictionaries, where they could before.
image

@nfx nfx added enhancement New feature or request codegen issues related to generated code labels Aug 4, 2023
@nfx nfx requested a review from mgyucht August 4, 2023 18:06
@nfx
Copy link
Contributor Author

nfx commented Aug 4, 2023

Once #262 is merged, rebase, forcepush, and retarget to main.

@codecov-commenter
Copy link

codecov-commenter commented Aug 4, 2023

Codecov Report

Patch coverage: 18.38% and project coverage change: -5.27% ⚠️

Comparison is base (c1c0886) 53.72% compared to head (e79f284) 48.46%.
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #264      +/-   ##
==========================================
- Coverage   53.72%   48.46%   -5.27%     
==========================================
  Files          33       33              
  Lines       19349    21718    +2369     
==========================================
+ Hits        10396    10526     +130     
- Misses       8953    11192    +2239     
Files Changed Coverage Δ
databricks/sdk/service/catalog.py 46.51% <ø> (-6.56%) ⬇️
databricks/sdk/service/compute.py 46.46% <ø> (-7.39%) ⬇️
databricks/sdk/service/iam.py 40.47% <ø> (-7.74%) ⬇️
databricks/sdk/service/jobs.py 48.48% <ø> (-7.72%) ⬇️
databricks/sdk/service/ml.py 47.02% <ø> (-2.80%) ⬇️
databricks/sdk/service/sql.py 50.14% <ø> (-5.89%) ⬇️
databricks/sdk/service/provisioning.py 43.69% <5.53%> (-6.87%) ⬇️
databricks/sdk/service/sharing.py 50.76% <5.60%> (-4.20%) ⬇️
databricks/sdk/service/billing.py 48.81% <7.75%> (-3.91%) ⬇️
databricks/sdk/service/oauth2.py 46.91% <11.42%> (-4.58%) ⬇️
... and 8 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nfx nfx changed the title Added strict method argument type validation Added strict runtime type validation for all @dataclass and method arguments Aug 4, 2023
@nfx nfx changed the title Added strict runtime type validation for all @dataclass and method arguments Added strict runtime type validation for all @dataclass'es and method arguments Aug 4, 2023
@nfx nfx requested a review from jasongrout-db August 4, 2023 19:01
Base automatically changed from remove-request-class to main August 7, 2023 09:04
nfx added 2 commits August 10, 2023 13:58
This PR removes `XxxRequest` classes that are referenced only as requests, effectively removing the undocumented `request=(XxxRequest(foo=1))` API. This will enforce validation on the field names for specific requests.

This PR also adds validation of custom types on the request level, so that it's clear also at the runtime level when an invalid request has been supplied.

remove validation (for now)

fmt

fix array of enums

Added strict method argument type validation

This PR adds strict type validation for generated argument types, like dataclasses and enums, giving clear error messages about expected type names.

add validation also to all nested fields

regen
@nfx nfx force-pushed the add-runtime-type-validation branch from 6c15d42 to 7a34d2a Compare August 10, 2023 12:15
@nfx
Copy link
Contributor Author

nfx commented Aug 10, 2023

integration tests pass

@nfx nfx removed the request for review from jasongrout-db August 10, 2023 12:43
@nfx nfx enabled auto-merge August 10, 2023 12:43
@nfx nfx added the ergonomics UX of SDK label Sep 25, 2023
auto-merge was automatically disabled November 23, 2023 15:14

Merge queue setting changed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codegen issues related to generated code enhancement New feature or request ergonomics UX of SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ISSUE] JobsAPI.create in v0.4.0 does not serialize the access_control_list correctly
2 participants