dlt-hub / verified-sources

Contribute to dlt verified sources 🔥
https://dlthub.com/docs/walkthroughs/add-a-verified-source
Apache License 2.0
52 stars 40 forks source link

rest_api: Request param incremental configuration should not accept keys that it ignores #518

Open willi-mueller opened 3 days ago

willi-mueller commented 3 days ago

dlt version

0.4.11

Source name

rest_api

Describe the problem

Currently,

 {
        "since": {
            "type": "incremental",
            "cursor_path": "updated_at",
            "initial_value": "2024-01-01",
            "end_value": "2024-01-31",
        },
    } 

results in:

dlt.sources.incremental(
        cursor_path="updated_at",
        initial_value="2024-01-01",
        end_value="2024-01-31",  # This is ineffective code that looks as if it's doing something
    )

Expected behavior

Instead of ignoring the end_value key it should throw a ValueError and explain that to specify an end_value the user has to create an incremental configuration at the resource level and not at the parameter level.

Steps to reproduce

param_config = {
    "since": {
        "type": "incremental",
        "cursor_path": "updated_at",
        "initial_value": "2024-01-01T00:00:00Z",
        "end_value": "2024-06-30T00:00:00Z",
    }
}

(incremental_obj, incremental_param, transform) = setup_incremental_object(
    param_config, None
)

incremental_with_init_and_end = dlt.sources.incremental(
        cursor_path="updated_at",
        initial_value="2024-01-01T00:00:00Z",
        end_value="2024-06-30T00:00:00Z",
    )

# Here the incremental object contains an end value but the incremental param only has the start value
assert incremental_with_init_and_end == incremental_obj
assert incremental_param == IncrementalParam(start="since", end=None)

How you are using the source?

I run this source in production.

Operating system

macOS

Runtime environment

Local

Python version

3.11

dlt destination

duckdb

Additional information

No response