首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有效的UUID不是有效的UUID

有效的UUID不是有效的UUID
EN

Stack Overflow用户
提问于 2017-08-31 21:46:47
回答 2查看 4.9K关注 0票数 8

我遇到了一个非常奇怪的问题,因为我得到的是一个有效的UUID不是有效的UUID,例如:

代码语言:javascript
复制
'fd31b6b5-325d-4b65-b496-d7e4d16c8a93' is not a valid UUID.

File "/opt/python/run/venv/lib/python3.4/site-packages/django/db/models/fields/__init__.py" in get_db_prep_value
  2371.                 value = uuid.UUID(value)

File "/usr/lib64/python3.4/uuid.py" in __init__
  134.             hex = hex.replace('urn:', '').replace('uuid:', '')


      During handling of the above exception ('UUID' object has no attribute 'replace'), another exception occurred:

我的模型有一个UUIDField作为pk,这个错误似乎是随机发生的,在我重新启动服务器之前不会停止运行,当服务器重新启动时,它可以正常工作,所以我在这里有点迷路,我在amazon中使用django 1.10.7,PostgreSQL9.6.3,python3.4.3。

编辑:

模型制造问题

代码语言:javascript
复制
class ReciboTransaccion(models.Model):    
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    ingreso = models.ForeignKey('banco.BaseTransaccion', related_name='recibo_ingreso',
                                on_delete=models.PROTECT,
                                null=True, blank=True,
                                editable=False)
    egreso = models.OneToOneField('banco.BaseTransaccion', related_name='recibo_egreso',
                                  on_delete=models.PROTECT,
                                  null=True, blank=True,
                                  editable=False)
    fecha = models.DateTimeField(auto_now_add=True)

模型'BaseTransaccion‘也有

代码语言:javascript
复制
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

编辑2:

触发此错误的代码如下

代码语言:javascript
复制
serial_movimientos = ReciboSerializer(recibos, many=True)

data = {
        'movimientos': serial_movimientos.data,  # Error happens here
    }

序列化程序是相当标准的(已删除序列化程序方法)

代码语言:javascript
复制
class ReciboSerializer(serializers.ModelSerializer):
    ingreso = serializers.SerializerMethodField()
    egresos = serializers.SerializerMethodField()
    descripcion = serializers.SerializerMethodField()
    monedero_generado = serializers.SerializerMethodField()
    reembolsada = serializers.SerializerMethodField()

    class Meta:
        model = ReciboTransaccion
        fields = ('ingreso', 'egresos', 'descripcion', 'monedero_generado', 'reembolsada', 'fecha', )

追踪的其他部分是:

代码语言:javascript
复制
File "/opt/python/run/venv/lib/python3.4/site-packages/django/core/handlers/exception.py" in inner
  42.             response = get_response(request)

File "/opt/python/run/venv/lib/python3.4/site-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "/opt/python/run/venv/lib/python3.4/site-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/opt/python/run/venv/lib/python3.4/site-packages/django/views/decorators/csrf.py" in wrapped_view
  58.         return view_func(*args, **kwargs)

File "/opt/python/current/app/myproject/main/ws.py" in index
  129.                 json_data = func(request)

File "/opt/python/current/app/myproject/main/ws.py" in get_datos_home
  534.         'movimientos': serial_movimientos.data,

File "/opt/python/run/venv/lib/python3.4/site-packages/rest_framework/serializers.py" in data
  739.         ret = super(ListSerializer, self).data

File "/opt/python/run/venv/lib/python3.4/site-packages/rest_framework/serializers.py" in data
  263.                 self._data = self.to_representation(self.instance)

File "/opt/python/run/venv/lib/python3.4/site-packages/rest_framework/serializers.py" in to_representation
  657.             self.child.to_representation(item) for item in iterable

File "/opt/python/run/venv/lib/python3.4/site-packages/django/db/models/query.py" in __iter__
  256.         self._fetch_all()

File "/opt/python/run/venv/lib/python3.4/site-packages/django/db/models/query.py" in _fetch_all
  1087.             self._result_cache = list(self.iterator())

File "/opt/python/run/venv/lib/python3.4/site-packages/django/db/models/query.py" in __iter__
  54.         results = compiler.execute_sql()

File "/opt/python/run/venv/lib/python3.4/site-packages/django/db/models/sql/compiler.py" in execute_sql
  824.             sql, params = self.as_sql()

File "/opt/python/run/venv/lib/python3.4/site-packages/django/db/models/sql/compiler.py" in as_sql
  376.             where, w_params = self.compile(self.where) if self.where is not None else ("", [])

File "/opt/python/run/venv/lib/python3.4/site-packages/django/db/models/sql/compiler.py" in compile
  353.             sql, params = node.as_sql(self, self.connection)

File "/opt/python/run/venv/lib/python3.4/site-packages/django/db/models/sql/where.py" in as_sql
  79.                 sql, params = compiler.compile(child)

File "/opt/python/run/venv/lib/python3.4/site-packages/django/db/models/sql/compiler.py" in compile
  353.             sql, params = node.as_sql(self, self.connection)

File "/opt/python/run/venv/lib/python3.4/site-packages/django/db/models/lookups.py" in as_sql
  297.         return super(In, self).as_sql(compiler, connection)

File "/opt/python/run/venv/lib/python3.4/site-packages/django/db/models/lookups.py" in as_sql
  156.         rhs_sql, rhs_params = self.process_rhs(compiler, connection)

File "/opt/python/run/venv/lib/python3.4/site-packages/django/db/models/lookups.py" in process_rhs
  284.             sqls, sqls_params = self.batch_process_rhs(compiler, connection, rhs)

File "/opt/python/run/venv/lib/python3.4/site-packages/django/db/models/lookups.py" in batch_process_rhs
  51.             _, params = self.get_db_prep_lookup(rhs, connection)

File "/opt/python/run/venv/lib/python3.4/site-packages/django/db/models/lookups.py" in get_db_prep_lookup
  181.             if self.get_db_prep_lookup_value_is_iterable else

File "/opt/python/run/venv/lib/python3.4/site-packages/django/db/models/lookups.py" in <listcomp>
  180.             [get_db_prep_value(v, connection, prepared=True) for v in value]

File "/opt/python/run/venv/lib/python3.4/site-packages/django/db/models/fields/__init__.py" in get_db_prep_value
  2373.                 raise TypeError(self.error_messages['invalid'] % {'value': value})
EN

回答 2

Stack Overflow用户

发布于 2019-02-02 14:09:07

找到了一个相关的Django问题wsgi发行。对我来说,他补充道:

代码语言:javascript
复制
WSGIApplicationGroup %{GLOBAL}

对于Apache配置来说,似乎已经起作用了。

票数 4
EN

Stack Overflow用户

发布于 2020-12-07 02:34:19

一定要阅读@Ivan的答案,他在答案中指出了描述这个问题的Django问题。

对于任何晚来的人(像我一样,在一两年后),如果您遇到相同的uwsgi问题,解决方案是修改Django项目中的uwsgi.ini文件,包括:

代码语言:javascript
复制
single-interpreter=true

例如,整个uwsgi.ini文件可能如下所示:

代码语言:javascript
复制
[uwsgi]
chdir=/opt/theapp/
module=yourdjangoproject.wsgi:application
mount=/secure/rest=yourdjangoproject.wsgi:application
home=/opt/theapp/venv3.8
processes=10
socket = 127.0.0.1:8000
single-interpreter=true
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45990550

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档