Есть у меня вот такой класс для типа Cube в Postgres
class CubeField(models.Field):
description = 'Cube Postgres Field'
def db_type(self, connection):
if self.is_engine_support(connection):
return 'cube'
else:
return 'text'
def get_db_prep_value(self, value, connection, prepared=True):
if isinstance(value, (str)):
s = value
if isinstance(value, (list, tuple)):
s = ','.join(str(si) for si in value)
if self.is_engine_support(connection):
return 'CUBE(array[{}])'.format(s)
else:
return s
Я создаю модель , создаю экземпляр класса и у него вызываю метод save и происходит :
File "./manage.py", line 21, in <module>
main()
File "./manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/usr/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/var/www/fdx.mimobaka.ru/fdx/fdx_search/management/commands/add_data.py", line 58, in handle
f.save()
File "/usr/lib/python3.6/site-packages/django/db/models/base.py", line 741, in save
force_update=force_update, update_fields=update_fields)
File "/usr/lib/python3.6/site-packages/django/db/models/base.py", line 779, in save_base
force_update, using, update_fields,
File "/usr/lib/python3.6/site-packages/django/db/models/base.py", line 870, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/usr/lib/python3.6/site-packages/django/db/models/base.py", line 908, in _do_insert
using=using, raw=raw)
File "/usr/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/django/db/models/query.py", line 1186, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/usr/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1335, in execute_sql
cursor.execute(sql, params)
File "/usr/lib/python3.6/site-packages/django/db/backends/utils.py", line 99, in execute
return super().execute(sql, params)
File "/usr/lib/python3.6/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/usr/lib/python3.6/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/usr/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/usr/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
django.db.utils.DataError: invalid input syntax for cube
LINE 1: ..."super_cube") VALUES (2, NULL, 55, 129, 130, 55, 1, 'CUBE(arra...
^
DETAIL: syntax error at or near "C"
Судя по всему результат из get_db_prep_value строка и orm сует её в кавычки
'CUBE(arra
что мне не надо , ситуация напоминает mark_safe для html но для sql .
Как избавиться от этих кавычек ? Что пропустил ?