Skip to content

Commit fa3d2ba

Browse files
fix: Neptune bulk load bad request (#2305)
1 parent 906b4d2 commit fa3d2ba

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

awswrangler/neptune/_client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# mypy: disable-error-code=name-defined
22
"""Amazon NeptuneClient Module."""
33

4+
import json
45
import logging
56
from typing import Any, Dict, List, Optional, TypedDict, Union, cast
67

@@ -378,7 +379,12 @@ def load(
378379

379380
url = f"https://{self.host}:{self.port}/loader"
380381

381-
req = self._prepare_request("POST", url, data=data)
382+
req = self._prepare_request(
383+
method="POST",
384+
url=url,
385+
data=json.dumps(data),
386+
headers={"Content-Type": "application/json; charset=utf-8"},
387+
)
382388
res = self._http_session.send(req)
383389

384390
_logger.debug(res)

tests/unit/test_neptune.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
import random
33
import string
44
import uuid
5-
from typing import Any, Dict
5+
from typing import Any, Dict, Optional
66

77
import numpy as np
88
import pytest # type: ignore
99
from gremlin_python.process.traversal import Direction, T
1010

1111
import awswrangler as wr
1212
import awswrangler.pandas as pd
13+
from awswrangler.neptune._client import BulkLoadParserConfiguration
1314

1415
from .._utils import extract_cloudformation_outputs
1516

@@ -259,8 +260,20 @@ def test_gremlin_bulk_load_error_when_files_present(
259260
)
260261

261262

263+
DEFAULT_PARSER_CONFIGURATION = BulkLoadParserConfiguration(
264+
namedGraphUri="http://aws.amazon.com/neptune/vocab/v01/DefaultNamedGraph",
265+
baseUri="http://aws.amazon.com/neptune/default",
266+
allowEmptyStrings=False,
267+
)
268+
269+
270+
@pytest.mark.parametrize("parser_config", [None, DEFAULT_PARSER_CONFIGURATION])
262271
def test_gremlin_bulk_load_from_files(
263-
neptune_endpoint: str, neptune_port: int, neptune_load_iam_role_arn: str, path: str
272+
neptune_endpoint: str,
273+
neptune_port: int,
274+
neptune_load_iam_role_arn: str,
275+
path: str,
276+
parser_config: Optional[BulkLoadParserConfiguration],
264277
) -> None:
265278
client = wr.neptune.connect(neptune_endpoint, neptune_port, iam_enabled=False)
266279

@@ -274,6 +287,7 @@ def test_gremlin_bulk_load_from_files(
274287
client=client,
275288
path=path,
276289
iam_role=neptune_load_iam_role_arn,
290+
parser_configuration=parser_config,
277291
)
278292
res_df = wr.neptune.execute_gremlin(client, f"g.V().hasLabel('{label}').valueMap().with(WithOptions.tokens)")
279293

0 commit comments

Comments
 (0)