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.

Issue with template code that worked before updating Django 3->4 (possibly postgresql 13->14)

See original GitHub issue

This is the entire traceback provided by Django:

Environment:


Request Method: GET
Request URL: http://192.168.2.155:8000/quotes/

Django Version: 4.0.8
Python Version: 3.10.8
Installed Applications:
['django.contrib.admin',
 'django.contrib.admindocs',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.flatpages',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'django.contrib.sitemaps',
 'django.contrib.humanize',
 'django.contrib.postgres',
 'django.forms',
 'crispy_forms',
 'bootstrapform',
 'pinax.messages',
 'pinax.notifications',
 'notifications',
 'haystack',
 'ircdriven',
 'django_filters',
 'martor',
 'formtools',
 'debug_toolbar',
 'django_gravatar',
 'django_extensions',
 'django_countries',
 'allauth',
 'allauth.account',
 'allauth.socialaccount',
 'allauth.socialaccount.providers.github',
 'allauth.socialaccount.providers.google',
 'rest_framework',
 'rest_framework.authtoken',
 'drf_spectacular',
 'friendship',
 'captcha',
 'mptt',
 'widget_tweaks',
 'machina',
 'machina.apps.forum',
 'machina.apps.forum_conversation',
 'machina.apps.forum_conversation.forum_attachments',
 'machina.apps.forum_conversation.forum_polls',
 'machina.apps.forum_feeds',
 'machina.apps.forum_moderation',
 'machina.apps.forum_search',
 'machina.apps.forum_tracking',
 'machina.apps.forum_member',
 'machina.apps.forum_permission',
 'django_nyt.apps.DjangoNytConfig',
 'sekizai',
 'sorl.thumbnail',
 'wiki.apps.WikiConfig',
 'wiki.plugins.attachments.apps.AttachmentsConfig',
 'wiki.plugins.editsection.apps.EditSectionConfig',
 'wiki.plugins.globalhistory.apps.GlobalHistoryConfig',
 'wiki.plugins.help.apps.HelpConfig',
 'wiki.plugins.images.apps.ImagesConfig',
 'wiki.plugins.links.apps.LinksConfig',
 'wiki.plugins.macros.apps.MacrosConfig',
 'wiki.plugins.notifications.apps.NotificationsConfig',
 'vote']
Installed Middleware:
['debug_toolbar.middleware.DebugToolbarMiddleware',
 'django.middleware.cache.UpdateCacheMiddleware',
 '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',
 'django.contrib.sites.middleware.CurrentSiteMiddleware',
 'machina.apps.forum_permission.middleware.ForumPermissionMiddleware',
 'django.middleware.cache.FetchFromCacheMiddleware',
 'ircdriven.middleware.TimezoneMiddleware']


Template error:
In template /home/daniel/Repos/website/templates/ircdriven/quotes/main.html, error at line 50
   operator does not exist: character varying = numeric
LINE 1: ...content_type_id" = 93 AND "vote_vote"."object_id" = 15663665...
                                                             ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.

   40 :                     <div class="card">
   41 :                         <div class="card-body elegant-color p-0">
   42 :                             <pre style="white-space: pre-wrap;" class="p-2 mb-0 white-text">
   43 : {{ quote.quote }}</pre>
   44 :                         </div>
   45 :                         <div class="card-footer m-0 p-1 px-2">
   46 :                             <div class="small text-muted d-inline">Submitted by <a class="black-text" href="{% url 'user_profile' quote.submitter.username %}">{{ quote.submitter.username }}</a></div>
   47 :                             <div class="float-right d-inline">
   48 :                                 <div class="badge badge-pill badge-dark d-inline">{{ quote.vote_score }}</div>
   49 :                                 {% if request.user.is_authenticated %}
   50 :                                  {% vote_exists quote request.user 0 as vote_up %} 
   51 :                                 {% vote_exists quote request.user 1 as vote_down %}
   52 :                                 <div class="form-inline d-inline">
   53 :                                     <form class="d-inline" action="{% url 'quotes_home' %}" method="post">
   54 :                                         {% csrf_token %}
   55 :                                         <input type="hidden" name="id" value="{{ quote.id }}" />
   56 :                                         <input type="hidden" name="vote" value="up" />
   57 :                                         <button class="btn btn-link p-0 m-0" {% if vote_up %}disabled="disabled"{% endif %} type="submit"><i class="fa-sharp fa-solid fa-arrow-alt-up fa-lg green-text"></i></button>
   58 :                                     </form>
   59 :                                     <form class="d-inline" action="{% url 'quotes_home' %}" method="post">
   60 :                                         {% csrf_token %}


Traceback (most recent call last):
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)

The above exception (operator does not exist: character varying = numeric
LINE 1: ...content_type_id" = 93 AND "vote_vote"."object_id" = 15663665...
                                                             ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.
) was the direct cause of the following exception:
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/daniel/Repos/website/ircdriven/views/quote.py", line 51, in quotes_page
    return render(request, 'ircdriven/quotes/main.html', context)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/shortcuts.py", line 24, in render
    content = loader.render_to_string(template_name, context, request, using=using)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/loader.py", line 62, in render_to_string
    return template.render(context, request)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/backends/django.py", line 62, in render
    return self.template.render(context)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/base.py", line 175, in render
    return self._render(context)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/test/utils.py", line 111, in instrumented_test_render
    return self.nodelist.render(context)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/base.py", line 958, in render_annotated
    return self.render(context)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/loader_tags.py", line 157, in render
    return compiled_parent._render(context)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/test/utils.py", line 111, in instrumented_test_render
    return self.nodelist.render(context)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/base.py", line 958, in render_annotated
    return self.render(context)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/classytags/core.py", line 151, in render
    return str(self.render_tag(context, **kwargs))
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/sekizai/templatetags/sekizai_tags.py", line 87, in render_tag
    rendered_contents = nodelist.render(context)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/base.py", line 958, in render_annotated
    return self.render(context)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/defaulttags.py", line 322, in render
    return nodelist.render(context)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/base.py", line 958, in render_annotated
    return self.render(context)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/loader_tags.py", line 63, in render
    result = block.nodelist.render(context)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/base.py", line 958, in render_annotated
    return self.render(context)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/defaulttags.py", line 238, in render
    nodelist.append(node.render_annotated(context))
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/base.py", line 958, in render_annotated
    return self.render(context)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/defaulttags.py", line 322, in render
    return nodelist.render(context)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/base.py", line 958, in render_annotated
    return self.render(context)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/template/library.py", line 239, in render
    output = self.func(*resolved_args, **resolved_kwargs)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/vote/templatetags/vote.py", line 15, in vote_exists
    return model.votes.exists(user.pk, action=action)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/vote/utils.py", line 12, in inner
    return func(self, *args, **kwargs)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/vote/managers.py", line 145, in exists
    ).exists()
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/db/models/query.py", line 892, in exists
    return self.query.has_results(using=self.db)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/db/models/sql/query.py", line 589, in has_results
    return compiler.has_results()
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1329, in has_results
    return bool(self.execute_sql(SINGLE))
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1361, in execute_sql
    cursor.execute(sql, params)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/db/backends/utils.py", line 103, in execute
    return super().execute(sql, params)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/db/backends/utils.py", line 84, in _execute
    with self.db.wrap_database_errors:
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/daniel/.pyenv/versions/website/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)

Exception Type: ProgrammingError at /quotes/
Exception Value: operator does not exist: character varying = numeric
LINE 1: ...content_type_id" = 93 AND "vote_vote"."object_id" = 15663665...
                                                             ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.

The main piece throwing this is:

   50 :                                  {% vote_exists quote request.user 0 as vote_up %} 
   51 :                                 {% vote_exists quote request.user 1 as vote_down %}

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
dshafer-godaddycommented, Dec 5, 2022

@shellfly I will continue to investigate and submit a PR if I can figure it out. If there is anything I can do for you, let me know 😃

0reactions
y2kbadbugcommented, Nov 23, 2022

So it appears to be an issue with Django 4.x. I finally updated my prod server from Django 3.2.x to 4.0.8, and now I am getting the same error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django not updated inside the docker cookiecutters template
My Django project that is created based on Cookiecutters is not updated in local development environment after I changed the source code, ...
Read more >
django-import-export Documentation - Read the Docs
django -import-export is available on the Python Package Index (PyPI), ... If set, lists the permission code that is required for users to ......
Read more >
Model instance reference - Django documentation
Model instance reference¶. This document describes the details of the Model API. It builds on the material presented in the model and database...
Read more >
Why does Postgres generate an already used PK value?
You are most likely tying to insert a row in a table for which the serial column sequence value is not updated ......
Read more >
Django CRUD (Create, Retrieve, Update, Delete) Function ...
Django is based on MVT (Model View Template) architecture and revolves around CRUD (Create, Retrieve, Update, Delete) operations.
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