先看一个报错:
gunicorn[121154]: ERROR: Internal Server Error: /sb/buildprogressnote/
Traceback (most recent call last):
File "/ymk_test/buildapi/my_venv/lib64/python3.8/site-packages/django/db/backends/utils.py", line 82, in _execute
return self.cursor.execute(sql)
psycopg2.errors.NumericValueOutOfRange: integer out of range
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/ymk_test/buildapi/my_venv/lib64/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/ymk_test/buildapi/my_venv/lib64/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/ymk_test/buildapi/restapi/restview.py", line 205, in __call__
return getattr(self, method)(request, *args, **kwargs)
File "/ymk_test/buildapi/restapi/restutils.py", line 264, in wrapper
data = func(*args, **kwargs)
File "/ymk_test/buildapi/restapi/restview.py", line 516, in GET
cursor.execute(
File "/ymk_test/buildapi/my_venv/lib64/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/ymk_test/buildapi/my_venv/lib64/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/ymk_test/buildapi/my_venv/lib64/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/ymk_test/buildapi/my_venv/lib64/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/ymk_test/buildapi/my_venv/lib64/python3.8/site-packages/django/db/backends/utils.py", line 82, in _execute
return self.cursor.execute(sql)
django.db.utils.DataError: integer out of range
这里,我打印了下报错的 sql 语句为:
cursor.execute("SELECT reltuples::int FROM pg_class WHERE relname = '%s'"
? ? ? ? ? ? ? ? ? ?% queryset.model._meta.db_table)
然后,就是报出上述错误,这里注意下,reltuples::int? ,由于查出的?reltuples 字段的数据量可能很大,所以对一些字段往往是可以直接添加数据类型的,这里用的是 int ,而 postgres 中 int 的最大值为:2147483647,这样一来,就有可能出现上述的报错了:psycopg2.errors.NumericValueOutOfRange: integer out of range?
完全就是由于 int 已经不足以表示字段 reltuples 的值了,因此,只需要将其换位 bigint 就可以了。
cursor.execute("SELECT reltuples::bigint FROM pg_class WHERE relname = '%s'"
% queryset.model._meta.db_table)
然后就不报错了。
|