GithubHelp home page GithubHelp logo

Comments (11)

bashu avatar bashu commented on August 17, 2024

and?

from django-hitcount.

Aneemes avatar Aneemes commented on August 17, 2024

I had an existing project based on django 1.11.4 which I upgraded to 3.2.5. The previous version of django-hitcount in use was 1.2.3 now when upgraded to 1.3.5.

The traceback indicates that the exception occurred in get_or_create method of the HitCount model in the hitcount package. The error message is HitCount matching query does not exist. Additionally, another error message was raised directly from the database back-end, stating that integer out of range is the direct cause of the error.

The error was encountered in the views.py file of the document application while trying to get a HitCount object for a particular object.(hit_count = HitCount.objects.get_for_object(self.object) ) The object does not exist in the database, and get_or_create method was called to create it. However, the integer value of the object's primary key seems to be out of the valid range.
It could be cause of the way hits is stored in the django-hitcount's model currently which is PositiveIntegerField.

from django-hitcount.

bashu avatar bashu commented on August 17, 2024

Were can I see the traceback? how can I reproduce it?

from django-hitcount.

Aneemes avatar Aneemes commented on August 17, 2024

`Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/documents/detail/a775d200-376d-44db-9d6d-f85e2c3f5a3a/

Django Version: 3.2.5
Python Version: 3.6.0
Installed Applications:
['jet',
'django.contrib.admin',
'django.contrib.sites',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.postgres.search',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.twitter',
'allauth.socialaccount.providers.google',
'crispy_forms',
'hitcount',
'star_ratings',
'analytical',
'bootstrap_pagination',
'admin_reorder',
'django_cleanup',
'rest_framework',
'rest_framework.authtoken',
'import_export',
'captcha',
'corsheaders',
'pustakalaya_apps.core',
'pustakalaya_apps.document',
'pustakalaya_apps.collection',
'pustakalaya_apps.audio',
'pustakalaya_apps.video',
'pustakalaya_apps.image',
'pustakalaya_apps.other',
'pustakalaya_apps.dashboard',
'pustakalaya_apps.pustakalaya_analytics',
'pustakalaya_apps.pustakalaya_search',
'pustakalaya_apps.pustakalaya_account',
'pustakalaya_apps.review_system',
'pustakalaya_apps.favourite_collection',
'pustakalaya_apps.show_featured',
'pustakalaya_apps.set_featured',
'pustakalaya_apps.software_downloads',
'pustakalaya_apps.interactive',
'pustakalaya_apps.accessibility',
'pustakalaya_apps.epub_reader',
'pustakalaya_apps.school']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
'admin_reorder.middleware.ModelAdminReorder']

Traceback (most recent call last):
  File "C:\django-upgrade\env\lib\site-packages\django\db\models\query.py", line 581, in get_or_create
    return self.get(**kwargs), False
  File "C:\django-upgrade\env\lib\site-packages\django\db\models\query.py", line 437, in get
    self.model._meta.object_name

During handling of the above exception (HitCount matching query does not exist.), another exception occurred:
  File "C:\django-upgrade\env\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)

The above exception (integer out of range
) was the direct cause of the following exception:
  File "C:\django-upgrade\env\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\django-upgrade\env\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\django-upgrade\env\lib\site-packages\django\views\generic\base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\django-upgrade\env\lib\site-packages\django\views\generic\base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "C:\django-upgrade\olen-elib\src\pustakalaya_apps\document\views.py", line 64, in get
    hit_count = HitCount.objects.get_for_object(self.object)
  File "C:\django-upgrade\env\lib\site-packages\hitcount\managers.py", line 14, in get_for_object
    content_type=ctype, object_pk=obj.pk)
  File "C:\django-upgrade\env\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "C:\django-upgrade\env\lib\site-packages\django\db\models\query.py", line 588, in get_or_create
    return self.create(**params), True
  File "C:\django-upgrade\env\lib\site-packages\django\db\models\query.py", line 453, in create
    obj.save(force_insert=True, using=self.db)
  File "C:\django-upgrade\env\lib\site-packages\django\db\models\base.py", line 727, in save
    force_update=force_update, update_fields=update_fields)
  File "C:\django-upgrade\env\lib\site-packages\django\db\models\base.py", line 765, in save_base
    force_update, using, update_fields,
  File "C:\django-upgrade\env\lib\site-packages\django\db\models\base.py", line 868, in _save_table
    results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
  File "C:\django-upgrade\env\lib\site-packages\django\db\models\base.py", line 908, in _do_insert
    using=using, raw=raw,
  File "C:\django-upgrade\env\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "C:\django-upgrade\env\lib\site-packages\django\db\models\query.py", line 1270, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
  File "C:\django-upgrade\env\lib\site-packages\django\db\models\sql\compiler.py", line 1416, in execute_sql
    cursor.execute(sql, params)
  File "C:\django-upgrade\env\lib\site-packages\django\db\backends\utils.py", line 98, in execute
    return super().execute(sql, params)
  File "C:\django-upgrade\env\lib\site-packages\django\db\backends\utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "C:\django-upgrade\env\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "C:\django-upgrade\env\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "C:\django-upgrade\env\lib\site-packages\django\db\utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:\django-upgrade\env\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)

Exception Type: DataError at /documents/detail/a775d200-376d-44db-9d6d-f85e2c3f5a3a/
Exception Value: integer out of range

from django-hitcount.

bashu avatar bashu commented on August 17, 2024

let me guess you do use uuid as primary key for this document, right?

from django-hitcount.

Aneemes avatar Aneemes commented on August 17, 2024

yes

from django-hitcount.

Aneemes avatar Aneemes commented on August 17, 2024

i think i left it on default

from django-hitcount.

bashu avatar bashu commented on August 17, 2024

follow the documentation, see here https://github.com/thornomad/django-hitcount/blob/develop/docs/models.rst#customization

define your own base hitcount class and override object_pk field you should TextField to store object's pk, instead of PositiveIntegerField

Good luck

from django-hitcount.

Aneemes avatar Aneemes commented on August 17, 2024

Sure, Thank You! I'll see if that will work

from django-hitcount.

Aneemes avatar Aneemes commented on August 17, 2024

Unfortunately that did not work, So i forked and modified the hitcount models to take in object_pk as UUIDDField.
Anyone facing the same issue can use the following fork:
https://github.com/Aneemes/django-hitcount.git

from django-hitcount.

bashu avatar bashu commented on August 17, 2024

What doesn't work?

from django-hitcount.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.