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

Fix files and events replicators #134

Merged
merged 7 commits into from
Nov 18, 2020
Merged

Fix files and events replicators #134

merged 7 commits into from
Nov 18, 2020

Conversation

maudeburkhalter
Copy link
Contributor

  • Add a 7th argument and set it to None for copy_events and copy_files functions in order to make them work again
  • Background: the addition of a 7th arg to replication.thread for use in TimeSeries has broken other resource copy_* fn-s.

* Add a 7th argument and set it to None for copy_events and copy_files functions in order to make them work again
* Background: the addition of a 7th arg to replication.thread for use in TimeSeries has broken other resource copy_* fn-s.
@cognite-cicd
Copy link

Checkmarx scan completed with the following findings

Lines Severity Category File Link

Copy link
Contributor

@gaetan-h gaetan-h left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@gaetan-h gaetan-h marked this pull request as draft November 11, 2020 12:58
@gaetan-h gaetan-h marked this pull request as ready for review November 11, 2020 12:59
@sceniclife
Copy link
Contributor

sceniclife commented Nov 11, 2020

Hey, thanks for the hotfix.

The bug also exists for Files also since it use the same replicator.thread function. (7th argument).
While adding a 7th argument and setting to null prevents the issue, it's not exactly neat. Now we have a dst_ts variable designated for time-series floating into events.py and possibly files.py.

The dst_ts feature was added to timeseries as List of specific time series external ids to replicate. To fix this issue correctly, we should add the feature to events.py and files.py respectively.

  1. Change the variable dst_ts to src_filter in timeseries.py and replication.py
  2. Change the parameters for replication.threads to
def thread(
    num_threads: int,
    copy,
    src_objects: List[Union[Event, FileMetadata, TimeSeries]],
    src_id_dst_obj: Dict[int, Union[Event, FileMetadata, TimeSeries]],
    src_dst_ids_assets: Dict[int, int],
    project_src: str,
    replicated_runtime: int,
    client: CogniteClient,
    src_filter: Optional[List[Union[Event, FileMetadata, TimeSeries]]] = None,
):
  1. Add the logic and variable src_filter onto events.py and files.py to filter by external_id (similar to time_series.py)
if target_external_ids:
    ts_src = client_src.time_series.retrieve_multiple(external_ids=target_external_ids, ignore_unknown_ids=True)
    try:
        ts_dst = client_dst.time_series.retrieve_multiple(external_ids=target_external_ids, ignore_unknown_ids=True)
    except CogniteNotFoundError:
        ts_dst = TimeSeriesList([])
else:
    ts_src = client_src.time_series.list(limit=None)
    ts_dst = client_dst.time_series.list(limit=None)
    logging.info(f"There are {len(ts_src)} existing time series in source ({project_src}).")
    logging.info(f"There are {len(ts_dst)} existing time series in destination ({project_dst}).")

Then it should all work with the intended features.

@gaetan-h
Copy link
Contributor

gaetan-h commented Nov 11, 2020 via email

@maudeburkhalter
Copy link
Contributor Author

@sceniclife yes, this was just a quick fix to restore the broken behavior. I agree that a more elegant solution should be implemented; I came across the bug while needing to use the replicator and pushed the fix to have a working version out there.

@sceniclife sceniclife mentioned this pull request Nov 11, 2020
@gaetan-h gaetan-h merged commit 0bec116 into master Nov 18, 2020
@gaetan-h gaetan-h deleted the fix-event-replicator branch November 18, 2020 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: copy_events() takes 6 positional arguments but 7 were given
5 participants