Comments (11)
and?
from django-hitcount.
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.
Were can I see the traceback? how can I reproduce it?
from django-hitcount.
`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.
let me guess you do use uuid as primary key for this document, right?
from django-hitcount.
yes
from django-hitcount.
i think i left it on default
from django-hitcount.
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.
Sure, Thank You! I'll see if that will work
from django-hitcount.
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.
What doesn't work?
from django-hitcount.
Related Issues (20)
- Only getting 10.0.0.1 when connecting via IPv6
- Django version 3 support? HOT 1
- Doesn't work with Django 3.1.3 HOT 2
- Would you like to add maintainers to the current project HOT 2
- Save by date feature HOT 1
- no such table: hitcount_blacklist_ip HOT 3
- Django 4.x: import of gettext failing HOT 5
- ImportError: cannot import name 'ugettext_lazy' from 'django.utils.translation' HOT 3
- BUG: hitcount_cleanup not working for big dataset
- Support for project with multiple Site ID
- Issue when running "python manage.py migrate --fake-initial". Resetting migrations HOT 1
- Delete hits from admin panel
- How to use it in Django REST framework? HOT 2
- Making request using JavaScript, hits is incrementing every request + 1
- Differentiate between bot and real user
- making the object_pk use uuid throws ProgrammingError error.
- Allow to search for pagetitle in admin interface
- Add HitCountViewMixin HOT 1
- Development + missing migrations
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-hitcount.