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

Adding output template to read requests #5054

Merged
merged 10 commits into from
Jul 13, 2024

Conversation

galvana
Copy link
Contributor

@galvana galvana commented Jul 2, 2024

Closes PROD-2209

Description Of Changes

Introduces the concept of "output templates" for read SaaSRequests. This allows the user to specify a template that will be used to generate each row of a collection response. This was done to allow param values (connector params, identity values, dataset reference values) to be aggregated in a read request and be used as input data for update/delete requests.

To demonstrate the usefulness of this new concept, I refactored the following integrations to use output templates instead of request overrides:

  • Adyen
  • AppsFlyer
  • Statsig

Code Changes

  • Added new ReadSaaSRequest schema to only allow the output field for read requests
  • Updated the base SaaSConnector class to support output templates
  • Minor refactor of SaaSQueryConfig
  • New tests for the validation functions of the SaaSRequest and ReadSaaSRequest schemas
  • Output template tests focused on SaaSConnector.retrieve_data()

Steps to Confirm

  • Integration tests

Pre-Merge Checklist

  • All CI Pipelines Succeeded
  • Issue Requirements are Met
  • Update CHANGELOG.md

Copy link

vercel bot commented Jul 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
fides-plus-nightly ⬜️ Ignored (Inspect) Visit Preview Jul 12, 2024 10:48pm

Copy link

cypress bot commented Jul 2, 2024

Passing run #8886 ↗︎

0 4 0 0 Flakiness 0
⚠️ You've recorded test results over your free plan limit.
Upgrade your plan to view test results.

Details:

Merge f27ed09 into 8dad9bb...
Project: fides Commit: 261f6831a9 ℹ️
Status: Passed Duration: 00:34 💡
Started: Jul 12, 2024 10:59 PM Ended: Jul 12, 2024 10:59 PM

Review all test suite changes for PR #5054 ↗︎

@galvana galvana requested a review from adamsachs July 7, 2024 04:32
@galvana galvana marked this pull request as ready for review July 8, 2024 15:01
@galvana galvana requested a review from a team as a code owner July 8, 2024 15:01
Copy link

codecov bot commented Jul 8, 2024

Codecov Report

Attention: Patch coverage is 98.41270% with 1 line in your changes missing coverage. Please review.

Project coverage is 86.50%. Comparing base (8dad9bb) to head (f27ed09).

Files Patch % Lines
src/fides/api/service/connectors/saas_connector.py 96.15% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5054      +/-   ##
==========================================
+ Coverage   86.42%   86.50%   +0.08%     
==========================================
  Files         356      353       -3     
  Lines       22181    22176       -5     
  Branches     2913     2920       +7     
==========================================
+ Hits        19169    19184      +15     
+ Misses       2497     2478      -19     
+ Partials      515      514       -1     

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

Copy link
Contributor

@adamsachs adamsachs left a comment

Choose a reason for hiding this comment

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

i like this new feature a lot @galvana! i think the implementation looks solid, just a few nits and then a question about whether it would be wise to have some more formal guard rails around the output template value.

i'll approve tentatively though and leave that to your discretion 👍

@@ -194,8 +194,8 @@ def validate_grouped_inputs(cls, values: Dict[str, Any]) -> Dict[str, Any]:

return values

@root_validator
def validate_override(cls, values: Dict[str, Any]) -> Dict[str, Any]:
@root_validator(allow_reuse=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: does this really need the allow_reuse=True? i thought this was used if you actually wanted to reuse the same function/method for multiple validators; in your case here, you're defining a new validate_request validator function in the ReadSaaSRequest now below, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, I wanted the validator on ReadSaaSRequest to override the validator on SaaSRequest but @root_validator is enough, I don't need allow_reuse

# This allows us to build an output object even if we didn't generate and execute
# any HTTP requests. This is useful if we just want to select specific input_data
# values to provide as row data to the mask_data function
if not read_request.path and read_request.output:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this may read a bit simpler and i think is equivalent?

Suggested change
if not read_request.path and read_request.output:
elif read_request.output:

if processed_row:
param_value_map[ALL_OBJECT_FIELDS] = processed_row
row = assign_placeholders(output_template, param_value_map)
result.append(json.loads(row)) # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

is this fully insured that it's valid, de-serializable JSON here? do we perhaps need some validation on the output field for the read request? (i'll leave a comment up there too)

that is used to format each collection result.
"""

output: Optional[str]
Copy link
Contributor

Choose a reason for hiding this comment

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

per comment below, just wondering if we should have some sort of validation here that this is a valid JSON template?

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 won't necessarily be valid JSON until the placeholders are evaluated, I'll just log out the invalid JSON further downstream if there are any parsing issues

@galvana galvana added the run unsafe ci checks Runs fides-related CI checks that require sensitive credentials label Jul 12, 2024
@galvana galvana merged commit 1957636 into main Jul 13, 2024
50 of 51 checks passed
@galvana galvana deleted the PROD-2209-add-extra-fields-to-saas-output branch July 13, 2024 01:30
Copy link

cypress bot commented Jul 13, 2024

Passing run #8891 ↗︎

0 4 0 0 Flakiness 0
⚠️ You've recorded test results over your free plan limit.
Upgrade your plan to view test results.

Details:

Adding output template to read requests (#5054)
Project: fides Commit: 1957636b7a
Status: Passed Duration: 00:35 💡
Started: Jul 13, 2024 1:41 AM Ended: Jul 13, 2024 1:42 AM

Review all test suite changes for PR #5054 ↗︎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run unsafe ci checks Runs fides-related CI checks that require sensitive credentials
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants