Skip to content

Fix IndexError: strip() before checking for empty value #54

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

Merged

Conversation

jvanmalder
Copy link
Contributor

I encountered the following error when trying to execute a bulk insert:

File "/usr/local/bin/redisgraph-bulk-loader", line 8, in <module>
    sys.exit(bulk_insert())
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/redisgraph_bulk_loader/bulk_insert.py", line 118, in bulk_insert
    process_entities(labels)
  File "/usr/local/lib/python3.9/site-packages/redisgraph_bulk_loader/bulk_insert.py", line 31, in process_entities
    entity.process_entities()
  File "/usr/local/lib/python3.9/site-packages/redisgraph_bulk_loader/label.py", line 66, in process_entities
    row_binary = self.pack_props(row)
  File "/usr/local/lib/python3.9/site-packages/redisgraph_bulk_loader/entity_file.py", line 275, in pack_props
    props.append(inferred_prop_to_binary(field))
  File "/usr/local/lib/python3.9/site-packages/redisgraph_bulk_loader/entity_file.py", line 148, in inferred_prop_to_binary
    if prop_val[0] == '[' and prop_val[-1] == ']':
IndexError: string index out of range

This happened because:

  1. Empty strings are handled first (see here)
  2. Then the property value is stripped (see here)
  3. Then the property value is accessed as if it wasn't empty (see here)

So in the case where the property value is just a bunch of space tokens, all of those are stripped away in step 2, firing off the IndexError in step 3.

It's quite a simple fix, by just stripping first before checking for the empty string.

Copy link
Contributor

@jeffreylovitz jeffreylovitz left a comment

Choose a reason for hiding this comment

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

Good catch, @jvanmalder! Thank you for the PR.

@jeffreylovitz jeffreylovitz merged commit 746c585 into RedisGraph:master Mar 2, 2021
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.

2 participants