表现:界面上报错:,刚登陆进去就能看到,点击执行也会出现。日志里报:
Traceback (most recent call last): File "/home/work/hue-3.10.0/desktop/libs/notebook/src/notebook/decorators.py", line 81, in decorator return func(*args, **kwargs) File "/home/work/hue-3.10.0/desktop/libs/notebook/src/notebook/api.py", line 124, in execute history = _historify(notebook, request.user) File "/home/work/hue-3.10.0/desktop/libs/notebook/src/notebook/api.py", line 319, in _historify is_history=True File "/home/work/hue-3.10.0/build/env/local/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/db/models/manager.py", line 157, in create return self.get_queryset().create(**kwargs) File "/home/work/hue-3.10.0/build/env/local/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/db/models/query.py", line 322, in create obj.save(force_insert=True, using=self.db) File "/home/work/hue-3.10.0/desktop/core/src/desktop/models.py", line 1138, in save home_dir = Document2.objects.get_home_directory(self.owner) File "/home/work/hue-3.10.0/desktop/core/src/desktop/models.py", line 935, in get_home_directory return self.get(owner=user, parent_directory=None, name=Document2.HOME_DIR, type=‘directory‘) File "/home/work/hue-3.10.0/build/env/local/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/db/models/manager.py", line 151, in get return self.get_queryset().get(*args, **kwargs) File "/home/work/hue-3.10.0/build/env/local/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/db/models/query.py", line 313, in get (self.model._meta.object_name, num)) MultipleObjectsReturned: get() returned more than one Document2 -- it returned 2!
复现步骤:已账号xxxx登录hue,即可看到异常.
ps: 有人在官网报此问题,http://gethue.com/how-to-fix-the-multipleobjectsreturned-error-in-hue/ 但官方没有给出解决方法.
根据stacktrace: File "/home/work/hue-3.10.0/desktop/core/src/desktop/models.py", line 935, in get_home_directory查到代码:
def get_home_directory(self, user): try: return self.get(owner=user, parent_directory=None, name=Document2.HOME_DIR, type=‘directory‘) except Document2.DoesNotExist: return self.create_user_directories(user)
是class Document2Manager的方法,怀疑是用户表中存的用户记录多了一条,所以查到两个home directory,查了auth_user表和useradmin_userprofile表,都正常。后又查表desktop_document2,按self.get()中的查询条件果然查到两行:
查别的正常账号,只有一条,解决方法应该是删掉多余的数据即可。
由于此表有个自连接的外键:CONSTRAINT `parent_directory_id_refs_id_4fe2babf` FOREIGN KEY (`parent_directory_id`) REFERENCES `desktop_document2` (`id`), 应先删除衍生数据,再删除根数据:
delete from desktop_document2 where parent_directory_id=7;
delete from desktop_document2 where id=7;
之后测试,果然解决。
为何会产生两条数据,原因未知。
时间: 2024-11-05 02:34:13