question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception always raised when saving a document using pypy but not when using cpython

See original GitHub issue

I have some code that saves data to Elasticsearch. It runs fine in Python 3.5.2 (cpython), but raises an exception when running on pypi3 6.0.0 (Python 3.5.3). Any ideas why?

File "/opt/venvs/parsedmarc/site-packages/parsedmarc/elastic.py", line 366, in save_forensic_report_to_elasticsearch
  forensic_doc.save()
File "/opt/venvs/parsedmarc/site-packages/elasticsearch_dsl/document.py", line 394, in save
  index=self._get_index(index),
File "/opt/venvs/parsedmarc/site-packages/elasticsearch_dsl/document.py", line 138, in _get_index
  raise ValidationException('You cannot write to a wildcard index.')
elasticsearch_dsl.exceptions.ValidationException: You cannot write to a wildcard index

Looking at document.py, that exception is only supposed to be raised when a save attempt is made on an index name that contains *.

I set the index name using a Meta class as as you can see here, and there is not any * in the index variable.

Here’s some basic sample code to reproduce the issue:

Note: you must have an Elasticsearch instance running to reproduce the issue.

from elasticsearch_dsl import DocType, Text, connections

class _ForensicReportDoc(DocType):
    class Meta:
        index = "sample_index"

    feedback_type = Text()

connections.create_connection(hosts=["127.0.0.1"], timeout=20)

doc = _ForensicReportDoc(feedback_type="foo")
doc.save()

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
honzakralcommented, Jul 17, 2018

Thank you for the report. The code that is responsible for setting the index name has been moved to class Index in 6.2.0 so now you have to do:

class _ForensicReportDoc(Document):
    class Index:
        name = 'sample_index'

Since it works for you in one environment and not another one is it possible that you have different versions?

Hope this helps!

0reactions
shivam05011996commented, Feb 21, 2019

While using elasticsearch-dsl 6.3.1 with elasticsearch 6.3.1. This is error is re-occuring, as the response dictionary doesnot have a key result, there is a key created with value True/False. This bug has been fixed locally, should create a PR

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does elasticsearch-dsl-py raise an exception on pypy but ...
I have some code that saves data to Elasticsearch. It runs fine in Python 3.5.2 (cpython), but raises an exception when running on...
Read more >
Why shouldn't I use PyPy over CPython if PyPy is 6.3 times ...
For an initial backup, which does lots of file chunking, pypy is great. But for subsequent backups which are mostly just updating timestamps,...
Read more >
How to fix Python KeyError Exceptions in simple steps?
Know about Python KeyError Exception. And learn how to handle exceptions in Python. A detailed guide to Errors and Exceptions in Python.
Read more >
How to perform exception handling in Python | Packt Hub
This example deals with opening the 'example.txt'. In such cases, when the called upon file is not found or does not exist then...
Read more >
8. Errors and Exceptions — Python 3.11.1 documentation
The error is caused by (or at least detected at) the token preceding the arrow: in the example, the error is detected at...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found