Skip to content

Commit d8f7119

Browse files
authored
Merge pull request #140 from multinet-app/csv-network-joins-fix
2 parents 017f4cd + 60859d6 commit d8f7119

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

multinet/api/tasks/upload/csv.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ def create_csv_network(workspace: Workspace, serializer):
214214
FILTER edge_doc.@TARGET_LINK_LOCAL == dd.@TARGET_LINK_FOREIGN
215215
return dd
216216
)
217+
218+
// Filter out missed joins
219+
FILTER source_doc != null && target_doc != null
220+
217221
// Add _from/_to to new doc, remove internal fields, insert into new coll
218222
LET excluded = APPEND(['_id', '_key', 'rev'], @EXCLUDED_COLS)
219223
LET new_edge_doc = MERGE(edge_doc, {'_from': source_doc._id, '_to': target_doc._id})

multinet/api/tests/test_csv_network.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,65 @@ def test_rest_create_csv_network_already_exists(
192192
)
193193
assert r.status_code == 400
194194
assert r.json() == 'Network already exists'
195+
196+
197+
@pytest.mark.django_db
198+
def test_create_csv_network_missing_joins(workspace, table_factory):
199+
edge_table: Table = table_factory(workspace=workspace)
200+
table1: Table = table_factory(workspace=workspace)
201+
table2: Table = table_factory(workspace=workspace)
202+
203+
# Create small network
204+
table1.put_rows(
205+
[
206+
{'id': 1, 'foo': 'bar'},
207+
# This wont match to anything
208+
{'id': 8, 'foo': 'baz'},
209+
]
210+
)
211+
table2.put_rows(
212+
[
213+
{'id': 2, 'bar': 'baz'},
214+
# This wont match to anything
215+
{'id': 40, 'bar': 'bat'},
216+
]
217+
)
218+
edge_table.put_rows(
219+
[
220+
{'a': 1, 'b': 2, 'c': 3},
221+
# This wont match to anything
222+
{'a': 100, 'b': 101, 'c': 3},
223+
]
224+
)
225+
226+
serializer = CSVNetworkCreateSerializer(
227+
data={
228+
'name': 'test',
229+
'edge': {
230+
'table': {
231+
'name': edge_table.name,
232+
'excluded': ['c'],
233+
},
234+
'source': {
235+
'local': 'a',
236+
'foreign': 'id',
237+
},
238+
'target': {
239+
'local': 'b',
240+
'foreign': 'id',
241+
},
242+
},
243+
'source_table': {
244+
'name': table1.name,
245+
'excluded': ['test'],
246+
},
247+
'target_table': {
248+
'name': table2.name,
249+
'excluded': [],
250+
},
251+
}
252+
)
253+
serializer.is_valid(raise_exception=True)
254+
255+
# Ensure no exceptions raised
256+
create_csv_network(workspace, serializer)

0 commit comments

Comments
 (0)