Repository: PrefectHQ/prefect-monte-carlo (language: python)

Issue:
edgeId is not a queryable field
On usage of the module, `create_or_replace_lineage_edge` tried to return an `edgeId` but this field is not part of a [LineageGraphEdge](https://apidocs.getmontecarlo.com/#definition-LineageGraphEdge)


Returned error:

`Finished in state Failed('Flow run encountered an exception. GqlError: Cannot query field "edgeId" on type "LineageGraphEdge".')`
Return the jobTs over edgeId as it is no-longer available.
After getting the error described in the issue and checking the montecarlo API docs.. there is no field `edgeId` to query. 

The only suitable field appears to be `jobTs`.

Closes [#28](https://github.com/PrefectHQ/prefect-monte-carlo/issues/28)

## Example
<!-- A code blurb is best. Changes to features should include an example that is executable by a new user. -->


## Checklist
- [x] References any related issue by including "Closes #<Issue Number>" or "Closes <Issue URL>".
  - If no issue exists and your change is not a small fix, please [create an issue](https://github.com/PrefectHQ/prefect-monte-carlo/issues/new/choose) first.
- [x] Includes tests or only affects documentation.
- [x] Passes `pre-commit` checks.
  - Run `pre-commit install && pre-commit run --all` locally for formatting and linting.
- [x] Includes screenshots of documentation updates.
  - Run `mkdocs serve` to view documentation locally.
- [x] Summarizes PR's changes in [CHANGELOG.md](https://github.com/PrefectHQ/prefect-monte-carlo/blob/main/CHANGELOG.md)



Discussion / hints:

hi @rudeb0y - apologies for the delay here.

this looks good to me - could you update the changelog? then I can merge and push out a release
Hi -@zzstoatzz sorry I thought I had

### Fixed
- `create_or_replace_lineage_edge` now returns the `jobTs` field as `edgeId` is not available.

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f6d8610..e93b52c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Security
 
+## v0.2.0
+
+Released July 20th, 2023.
+
+### Fixed
+- `create_or_replace_lineage_edge` now returns the `jobTs` field as `edgeId` is not available. - [#31](https://github.com/PrefectHQ/prefect-monte-carlo/pull/31)
+
 ## v0.1.0
 
 Released October 14th, 2022.
diff --git a/prefect_monte_carlo/lineage.py b/prefect_monte_carlo/lineage.py
index 5aafb17..9eebf60 100644
--- a/prefect_monte_carlo/lineage.py
+++ b/prefect_monte_carlo/lineage.py
@@ -92,7 +92,7 @@ def monte_carlo_orchestrator():
             # `create_or_update_lineage` is a flow, so this will be a subflow run
             # `extra_tags` are added to both the `source` and `destination` nodes
             create_or_update_lineage(
-                monte_carlo_credentials=MonteCarloCredentials.load("my-mc-creds)
+                monte_carlo_credentials=MonteCarloCredentials.load("my-mc-creds")
                 source=source,
                 destination=destination,
                 expire_at=datetime.now() + timedelta(days=10),
@@ -141,16 +141,19 @@ def monte_carlo_orchestrator():
     )
 
     # edge between source and destination nodes
-    edge_id = await create_or_update_lineage_edge(
+    job_timestamp = await create_or_update_lineage_edge(
         monte_carlo_credentials=monte_carlo_credentials,
         source=source,
         destination=destination,
         expire_at=expire_at,
     )
 
-    logger.info(f"Created or updated a destination lineage edge: {edge_id}")
+    logger.info(
+        f"Created or updated a destination a lineage edge between "
+        f"{source_node_url} and {destination_node_url}"
+    )
 
-    return edge_id
+    return job_timestamp
 
 
 @task(
@@ -247,7 +250,7 @@ async def create_or_update_lineage_edge(
     source: MonteCarloLineageNode,
     destination: MonteCarloLineageNode,
     expire_at: Optional[datetime] = None,
-) -> str:
+) -> int:
     """Create or update a Monte Carlo lineage edge via the GraphQL API.
 
     Args:
@@ -259,7 +262,7 @@ async def create_or_update_lineage_edge(
             the lineage edge will expire after 1 day.
 
     Returns:
-        The `edgeId` of the created or updated lineage edge.
+        The timestamp of the job that created or updated the lineage edge.
 
     Example:
         Create a lineage edge between a source table and a destination table:
@@ -320,7 +323,7 @@ def my_monte_carlo_flow():
             expireAt: $expire_at
             ){
             edge{
-                edgeId
+                jobTs
             }
             }
         }
@@ -338,6 +341,6 @@ def my_monte_carlo_flow():
 
     response = client(query=query, variables=variables)
 
-    edge_id = response["create_or_update_lineage_edge"]["edge"]["edge_id"]
+    job_timestamp = response["create_or_update_lineage_edge"]["edge"]["jobTs"]
 
-    return edge_id
+    return job_timestamp


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
index c6a3437..cc81cbb 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -174,19 +174,23 @@ def mock_edge_id():
     return "e3546a7dc6ee45f0eb63fda79dbc5de4994ffe2471c136aa057b95d3f9e5bd2e"
 
 
+@pytest.fixture
+def mock_job_ts():
+    return 1639478400
+
+
 @pytest.fixture
 def mock_create_or_update_node_response(mock_mcon):
     return {"create_or_update_lineage_node": {"node": {"mcon": mock_mcon}}}
 
 
 @pytest.fixture
-def mock_create_or_update_edge_response(mock_edge_id):
-    return {"create_or_update_lineage_edge": {"edge": {"edge_id": mock_edge_id}}}
+def mock_create_or_update_edge_response(mock_job_ts):
+    return {"create_or_update_lineage_edge": {"edge": {"jobTs": mock_job_ts}}}
 
 
 @pytest.fixture
 def mock_create_or_update_lineage_node(monkeypatch, mock_mcon):
-
     future = Future()
     future.set_result(mock_mcon)
 
@@ -200,7 +204,6 @@ def mock_create_or_update_lineage_node(monkeypatch, mock_mcon):
 def mock_create_or_update_lineage_node_response(
     monkeypatch, mock_create_or_update_node_response
 ):
-
     monkeypatch.setattr(
         "pycarlo.core.Client.__call__",
         MagicMock(return_value=mock_create_or_update_node_response),
@@ -211,7 +214,6 @@ def mock_create_or_update_lineage_node_response(
 def mock_create_or_update_lineage_edge_response(
     monkeypatch, mock_create_or_update_edge_response
 ):
-
     monkeypatch.setattr(
         "pycarlo.core.Client.__call__",
         MagicMock(return_value=mock_create_or_update_edge_response),
@@ -220,7 +222,6 @@ def mock_create_or_update_lineage_edge_response(
 
 @pytest.fixture
 def mock_create_or_update_lineage_edge(monkeypatch, mock_edge_id):
-
     future = Future()
     future.set_result(mock_edge_id)
 
diff --git a/tests/test_credentials.py b/tests/test_credentials.py
index 7569e43..bf679c2 100644
--- a/tests/test_credentials.py
+++ b/tests/test_credentials.py
@@ -2,7 +2,6 @@
 
 
 async def test_monte_carlo_credentials_get_client(monte_carlo_creds):
-
     mc_client = monte_carlo_creds.get_client()
 
     assert isinstance(mc_client, Client)
diff --git a/tests/test_lineage.py b/tests/test_lineage.py
index fd39672..5cfc34a 100644
--- a/tests/test_lineage.py
+++ b/tests/test_lineage.py
@@ -17,7 +17,6 @@ async def test_create_or_update_lineage(
     mock_create_or_update_lineage_node,
     mock_create_or_update_lineage_edge,
 ):
-
     edge_id = await create_or_update_lineage(
         monte_carlo_credentials=monte_carlo_creds,
         source=mock_source_model,
@@ -34,7 +33,6 @@ async def test_create_or_update_lineage_with_extra_tags(
     mock_create_or_update_lineage_node,
     mock_create_or_update_lineage_edge,
 ):
-
     edge_id = await create_or_update_lineage(
         monte_carlo_credentials=monte_carlo_creds,
         source=mock_source_model,
@@ -64,7 +62,6 @@ async def test_create_or_update_lineage_with_bad_extra_tags(
 async def test_create_or_update_lineage_source_with_bad_tags(
     mock_destination_model, monte_carlo_creds
 ):
-
     source_with_bad_tags = dict(
         node_name="source_dataset",
         object_id="source_dataset",
@@ -82,7 +79,6 @@ async def test_create_or_update_lineage_source_with_bad_tags(
 async def test_create_or_update_lineage_destination_with_bad_tags(
     mock_source_model, monte_carlo_creds
 ):
-
     destination_with_bad_tags = dict(
         node_name="destination_dataset",
         object_id="destination_dataset",
@@ -102,7 +98,6 @@ async def test_create_or_update_lineage_node_using_kwargs(
 ):
     @flow
     async def test_flow():
-
         return await create_or_update_lineage_node(
             monte_carlo_credentials=monte_carlo_creds,
             node_name="test_node",
@@ -129,7 +124,6 @@ async def test_create_or_update_lineage_node_using_model(
 
     @flow
     async def test_flow():
-
         return await create_or_update_lineage_node(
             monte_carlo_credentials=monte_carlo_creds, **node_model.dict()
         )
@@ -155,4 +149,4 @@ async def test_flow():
 
     edge_id = await test_flow()
 
-    assert edge_id == "e3546a7dc6ee45f0eb63fda79dbc5de4994ffe2471c136aa057b95d3f9e5bd2e"
+    assert edge_id == 1639478400