In my rest stream whenever I call self.context it'...
# getting-started
c
In my rest stream whenever I call self.context it's empty and run into the same issue with get_starting_timestamp despite having a valid state for the pipeline in meltano.db (which updates on each run as expected) Any idea how to get the stream to print the current context/extract the starting timestamp in the most simple way?
e
Hi @Caleb Hopkins! Does you plugin in
meltano.yml
have the
state
capability? https://docs.meltano.com/reference/plugin-definition-syntax/#capabilities
đź’Ż 1
👍 1
c
Hey thanks for responding! I do have that set both in the project I'm using it in and the project the tap's written in
Currently looks like this in the project i'm importing it to for local dev
Copy code
plugins:
  extractors:
  - name: tap-smartsheetresourcemanagement
    namespace: tap_smartsheetresourcemanagement
    pip_url: ../tap-smartsheetresourcemanagement
    executable: tap-smartsheetresourcemanagement
    config:
      auth_token: $SSRM_AUTH_TOKEN
    select:
    - '!*.*.*'
    - '*.*'
    metadata:
      users:
        replication_method: INCREMENTAL
        replication_key:
        - updated_at
    capabilities:
    - state
Right now I'm asserting context is not none for get_url_params in my 'Users' rest stream, but it's none so errors out - wondering if I need to explicitly inherit it from the Rest Stream? Or explicitly pass it somewhere?
e
> Right now I'm asserting context is not none for get_url_params in my 'Users' rest stream, but it's none so errors out The context can be
None
and it shouldn't be an issue. Cases where it shouldn't be `None`: • Child streams • Partitioned streams (e.g. override
Stream.partitions
) > but it's none so errors out Do you know the line of code where it's erroring out? Are you trying to access the context directly or just passing it to
self.*get_starting_timestamp(...)*
?
c
Not sure if this counts as a child stream? I am trying to access the stored state to filter old increments (since the api doesn't directly support that). First level: class SmartsheetResourceManagementStream(RESTStream): current stream: class UsersStream(SmartsheetResourceManagementStream): in user's stream I've made get_url_params and that's where I'm asserting the context shouldn't be None
Copy code
def get_url_params(
        self,
        context: Context | None,  # noqa: ARG002
        next_page_token: Any | None,  # noqa: ANN401
    ) -> dict[str, Any]:
        """Return a dictionary of values to be used in URL parameterization.

        Args:
            context: The stream context.
            next_page_token: The next page index or value.

        Returns:
            A dictionary of URL query parameters.
        """
        # Assert that context is not None
        assert self.get_starting_timestamp(self.context) is not None, "Starting timestamp is None in get_url_params"
wondering why nothing's getting passed for the context in this case and if that's how it's supposed to be then what the best way to get that incremental timestamp cutoff is for this stream
e
> Not sure if this counts as a child stream? A child stream defines a
parent_stream_type
, so that's probably not your case https://github.com/edgarrmondragon/tap-neon/blob/61c8d773f2950b830079f99ab0adba7d00018684/tap_neon/streams.py#L70 Does your stream define a
replication_key
? https://github.com/edgarrmondragon/tap-pushbullet/blob/d68030dca06d91f683ba59c546e0dcff12050ae7/tap_pushbullet/streams.py#L115
c
Got it, yes, I'm using updated_at as the replication key and looks like it's getting written out to meltano.db correctly Debug log:
Copy code
Added to state dev:tap-smartsheetresourcemanagement-to-target-jsonl state payload {'singer_state': {'bookmarks': {'users': {'replication_key': 'updated_at', 'replication_key_value': '2024-09-19T14:42:46Z'}}}}
Just wondering how to get at that replication_key_value in subsequent runs
e
Gotcha,
self.get_starting_timestamp
should give you what you want then. How are you invoking the tap?
c
Okay sweet, yeah that's the issue is it just gives none every time. I'm using meltano run:
Copy code
meltano run tap-smartsheetresourcemanagement target-jsonl
so in the class that's one down from RESTStream, that method is finding it as well as the context it looks like, but calling the context in my subclass is None, might just be a python thing I'm missing here. Think I'm good to troubleshoot now, thanks for the help
👍 1