Django queryset returning corrupted value

145 views
Skip to first unread message

Web Architect

unread,
Oct 6, 2017, 1:16:21 PM10/6/17
to Django users
Hi,

We have running an ecommerce site using Django 1.8.13. It has been running fine for a year. But suddenly the django querysets are returning corrupted values. I am completely clueless why this is happening. Like a model field is of type SlugField but queryset is returning long.

Would really appreciate if anyone could throw some light on how to fix the above issue. When I check the values in MySQL DB using PhpMyAdmin and everything is fine.

Thanks,
Pinakee

Antonis Christofides

unread,
Oct 6, 2017, 2:19:04 PM10/6/17
to django...@googlegroups.com
Hi,

could you show the code that defines the slugfield, the queryset that is returning the wrong value, full error message and traceback (if available), and the version of your OS and RDBMS?

It doesn't matter if the problem is more general; let's focus on one specific manifestation of it.

Regards,

Antonis

Web Architect

unread,
Oct 7, 2017, 4:40:35 AM10/7/17
to Django users
Hi Antonis,

Thanks for your response:

Following is the model:

from treebeard.mp_tree import MP_Node

@python_2_unicode_compatible
[docs]class AbstractCategory(MP_Node): """ A product category. Merely used for navigational purposes; has no effects on business logic. Uses django-treebeard. """ name = models.CharField(_('Name'), max_length=255, db_index=True) description = models.TextField(_('Description'), blank=True) image = models.ImageField(_('Image'), upload_to='categories', blank=True, null=True, max_length=255) slug = models.SlugField(_('Slug'), max_length=255, db_index=True)

Following is the queryset:

 >>>cat=category.objects.get(pk=11)

>>> cat

Traceback (most recent call last):

  File "<console>", line 1, in <module>

  File "/home/pinakee/oscar_v1/lib/python2.7/site-packages/django/db/models/base.py", line 496, in __repr__

    u = six.text_type(self)

  File "/home/pinakee/oscar_v1/lib/python2.7/site-packages/oscar/apps/catalogue/abstract_models.py", line 102, in __str__

    return self.full_name

  File "/home/waltzz/jivaana/jivaana_custom/catalogue/models.py", line 61, in full_name

    cache_key = self.slug + '_full_name'

TypeError: unsupported operand type(s) for +: 'long' and 'str'

>>> cat.slug

3L

The reason above exception is coming because cat.slug is long and not string as it is supposed to be.

MySQL Version:

mysql -V

mysql  Ver 14.14 Distrib 5.5.48, for Linux (x86_64) using readline 5.1

OS:

2.6.32-504.30.3.el6.x86_64

Thanks.

Antonis Christofides

unread,
Oct 8, 2017, 4:24:20 PM10/8/17
to django...@googlegroups.com

Hi,

this is very strange of course. I doubt it has anything to do with MySQL, because even if MySQL had done something wrong and had returned a long in place of a string, the Django ORM should have caught that and raised an error earlier. So the problem must be in Django. (But of course with such a strange problem anything is possible).

I'd first try to clean up the Python compiled files (remove them), remove and recreate the virtualenv, and restart Django. Also check the disk space in the machine.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0fb7769f-409a-4951-9e2d-4807f0873c16%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Web Architect

unread,
Oct 9, 2017, 3:18:13 AM10/9/17
to Django users
Hi Antonis,

Thanks for your response. You are right, The issue wasn't in MySQL or even Django ORM. We were using Cachalot (http://django-cachalot.readthedocs.io/en/latest/) for query caching which was causing the issue. Disabling cachalot fixed the issue. Would need to look more into query caching  to use it properly without issues.

Thanks.
Reply all
Reply to author
Forward
0 new messages