pysolr icon indicating copy to clipboard operation
pysolr copied to clipboard

Unable to create a core

Open Dimfred opened this issue 5 years ago • 2 comments

I have

  • [X] Tested with the latest release
  • [ ] Tested with the current master branch
  • [ ] Searched for similar existing issues

Expected behaviour

pysolr creates a new core

Actual behaviour

pysolr does not create a core

Steps to reproduce the behaviour

  1. admin = pysolr.SolrCoreAdmin("http://localhost:8983/solr/admin/cores"
  2. admin.create("corename", "<SOLR_ROOT>/server/solr/configsets/_default/conf")

Configuration

  • Operating system version: Ubuntu 20.04
  • Search engine version: 8.5.1
  • Python version: 3.7.3
  • pysolr version: 3.9.0

Could fix it with

replaced: https://github.com/django-haystack/pysolr/blob/master/pysolr.py#L1307

resp = requests.get(url, data=safe_url_encode(params), headers=headers) with resp = requests.get(url, data=params, headers=headers)

Dimfred avatar May 08 '20 09:05 Dimfred

I'm experiencing this same issue on:

  • OS: Ubuntu 18.04
  • Solr: 8.6.0
  • Python: 3.6.9
  • Pysolr: 3.9.0

Did the requests library change how it handles its data argument? params is a dict in that method while safe_urlencode() serializes it to a url-encoded string.

cpburnz avatar Aug 11 '20 22:08 cpburnz

Here's an example without modifying SolrCoreAdmin:

import pysolr
admin = pysolr.SolrCoreAdmin('http://localhost:8983/solr/admin/cores')
resp = admin.create('mytest')
print(resp)

This will print:

{
  "responseHeader":{
    "status":0,
    "QTime":0},
  "initFailures":{},
  "status":{}}

And Solr will log:

2020-08-12 15:02:56.786 INFO  (qtp491273700-19) [   ] o.a.s.s.HttpSolrCall [admin] webapp=null path=/admin/cores params={} status=0 QTime=0

Solr did not attempt to create the mytest core. It does not appear to be passing the expected parameters in the request.


Now if I modify SolrCoreAdmin._get_url() to remove the call to safe_urlencode(), and run the exact same code, it will print:

{
  "responseHeader":{
    "status":400,
    "QTime":6},
  "error":{
    "metadata":[
      "error-class","org.apache.solr.common.SolrException",
      "root-error-class","org.apache.solr.core.SolrResourceNotFoundException"],
    "msg":"Error CREATEing SolrCore 'mytest': Unable to create core [mytest] Caused by: Can't find resource 'solrconfig.xml' in classpath or '/var/solr/data/cores/mytest'",
    "code":400}}

And Solr will log:

2020-08-12 15:03:25.188 INFO  (qtp491273700-18) [   x:mytest] o.a.s.h.a.CoreAdminOperation core create command schema=schema.xml&name=mytest&action=CREATE&config=solrconfig.xml&instanceDir=mytest
2020-08-12 15:03:25.193 ERROR (qtp491273700-18) [   ] o.a.s.h.RequestHandlerBase org.apache.solr.common.SolrException: Error CREATEing SolrCore 'mytest': Unable to create core [mytest] Caused by: Can't find resource 'solrconfig.xml' in classpath or '/var/solr/data/cores/mytest'
        at org.apache.solr.core.CoreContainer.create(CoreContainer.java:1312)
        ...

2020-08-12 15:03:25.193 INFO  (qtp491273700-18) [   ] o.a.s.s.HttpSolrCall [admin] webapp=null path=/admin/cores params={schema=schema.xml&name=mytest&action=CREATE&config=solrconfig.xml&instanceDir=mytest} status=400 QTime=6

This error is the expected behavior. Solr is now attempting to create the mytest core but I never created solrconfig.xml.

cpburnz avatar Aug 12 '20 15:08 cpburnz