Area: Observability Issues
Sub-Area: Assertion Configuration
Applies to: Cloud
Issue
When you create an assertion with the DataHub Cloud Python SDK and set schedule=None, the assertion still runs on a daily schedule. The SDK default is the cron schedule "0 0 * * *" (daily at midnight, in the local timezone of the machine running the SDK). You may expect an assertion with no schedule that you only run on demand.
You Might Be Asking
- Why does the SDK create a daily schedule when I don't give one?
- Can I stop an assertion from running automatically when I use the SDK?
- Can I still run a stopped assertion manually?
Cause
The SDK uses a default schedule when you don't provide one. This matches the UI default. On create, the SDK uses the default daily schedule or the schedule you provide. On update, it keeps the existing schedule or uses the one you provide.
Solution
You create assertions with the keyword-only client.assertions.sync_*_assertion methods, for example sync_freshness_assertion, sync_volume_assertion and sync_sql_assertion. sync_freshness_assertion takes schedule (a cron string or CronScheduleClass) and enabled as keyword arguments.
Option 1: Set an explicit schedule
Pass a cron expression to control when the assertion runs:
client.assertions.sync_freshness_assertion(
dataset_urn=dataset_urn,
schedule="0 9 * * MON", # 9 AM every Monday
enabled=True,
)
Option 2: Stop the assertion so it doesn't run on its schedule
enabled defaults to True on create. Set enabled=False to set the assertion's monitor to INACTIVE (stopped). A stopped assertion does not run on its schedule.
client.assertions.sync_freshness_assertion(
dataset_urn=dataset_urn,
enabled=False,
)
A stopped assertion is not a "manual-only" assertion. In the UI, the Run action is disabled while the assertion is stopped. Its tooltip reads "This assertion is currently stopped! Start the assertion to run." The action is also disabled when you can't edit the assertion and when the assertion is bucketed. It appears only for native or inferred (smart) assertions that have a monitor, and only when on-demand runs are enabled for your instance. To run from the UI, Start the assertion first.
Option 3: Run the assertion on demand through the API
The GraphQL API has these mutations for native assertions:
-
runAssertion(urn, saveResult, parameters, async)runs one assertion. -
runAssertions(urns, saveResults, parameters, async)runs up to 20 assertions.
Both calls time out after 30 seconds. When async is true they return null, and you read the results from the assertion run events.
A third mutation runs the assertions associated with an asset. It omits non-native assertions. See Running assertions on demand for its arguments.
To be safe, Start the assertion before you run it through the API.