Opened 22 months ago

Closed 22 months ago

Last modified 22 months ago

#34299 closed Uncategorized (invalid)

'builtin_function_or_method' object has no attribute 'split' error in sql/query

Reported by: Stuart Chalk Owned by: nobody
Component: Database layer (models, ORM) Version: 4.1
Severity: Normal Keywords: builtin_function_or_method, split error
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Doing the follow search I get the error in the summary:

def search(request):
    """ search of the unit strings """
    term = request.GET.get("q")
    if term:
        strngs = Strngs.objects.filter(string=term).values_list(id, flat=True)
        if strngs:
            units = Units.objects.select_related('representations').get(representations__strng_id__in=strngs)
            if len(units) == 1:
                unit = units[0]
                return redirect('/units/view/' + str(unit.id))
            else:
                return render(request, "../templates/search.html", {'units': units, 'term': term})
        else:
            return redirect('/')
    else:
        return redirect('/')

The trackback is as follows:

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/search?q=amp

Django Version: 4.1.5
Python Version: 3.10.9
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'calculations',
 'dashboard',
 'units',
 'unitsystems',
 'repsystems',
 'constants',
 'umisconfig',
 'charts']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback (most recent call last):
  File "/Users/n00002621/.local/share/virtualenvs/nist_umis-6UcDd8EB/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/Users/n00002621/.local/share/virtualenvs/nist_umis-6UcDd8EB/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/n00002621/PycharmProjects/nist_umis/units/views.py", line 95, in search
    strngs = Strngs.objects.filter(string=term).values_list(id, flat=True)
  File "/Users/n00002621/.local/share/virtualenvs/nist_umis-6UcDd8EB/lib/python3.10/site-packages/django/db/models/query.py", line 1330, in values_list
    clone = self._values(*_fields, **expressions)
  File "/Users/n00002621/.local/share/virtualenvs/nist_umis-6UcDd8EB/lib/python3.10/site-packages/django/db/models/query.py", line 1293, in _values
    clone.query.set_values(fields)
  File "/Users/n00002621/.local/share/virtualenvs/nist_umis-6UcDd8EB/lib/python3.10/site-packages/django/db/models/sql/query.py", line 2437, in set_values
    self.add_fields(field_names, True)
  File "/Users/n00002621/.local/share/virtualenvs/nist_umis-6UcDd8EB/lib/python3.10/site-packages/django/db/models/sql/query.py", line 2143, in add_fields
    name.split(LOOKUP_SEP), opts, alias, allow_many=allow_m2m

Exception Type: AttributeError at /search
Exception Value: 'builtin_function_or_method' object has no attribute 'split'

Change History (2)

comment:1 by Tim Graham, 22 months ago

Resolution: invalid
Status: newclosed

You have a typo in your code: values_list(id, flat=True) is missing quotes around "id". In the future, please use TicketClosingReasons/UseSupportChannels to confirm a bug in Django before creating a ticket here. Thanks!

comment:2 by Stuart Chalk, 22 months ago

Darn, so sorry for reporting such a simple coding error.

Note: See TracTickets for help on using tickets.
Back to Top