我有一个运行mysql数据库的网站,使用的sql-alchemy包突然坏了。我做了一些研究,发现预期的问题是最新的sql-alchemy更新正在向flask-admin交付一个比预期更多的值
"cls, key = identity_key(instance=obj)"
Source
建议的修复是编辑文件以接受第三个项目,但我无法使用我在环境中拥有的权限执行此操作。
另一个答案链接到github上的回购,但我无法弄清楚这对我有什么帮助。我对此非常陌生,而且我不知道我是否应该克隆回购或者如果我是这样做的话应该如何做到。
感谢任何帮助!
这是错误转储
2018-01-22 20:01:59,593:[2018-01-22 20:01:59,592]应用中的错误: / reservation / add [GET]例外2018-01-22 20:01:59,594: 追溯(最近一次通话):2018-01-22 20:01:59,594:
文件" fakepath / flask / app.py",1982年,在wsgi_app中2018-01-22 20:01:59,594:response = self.full_dispatch_request()2018-01-22 20:01:59,594:File" fakepath / flask / app.py",1614行, 在full_dispatch_request
2018-01-22 20:01:59,594:rv = self.handle_user_exception(e)
2018-01-22 20:01:59,595:档案 " fakepath / flask / app.py",第1517行,在handle_user_exception2018-01-22 20:01:59,595:reraise(exc_type,exc_value,tb)2018-01-22 20:01:59,595:文件" fakepath / flask / _compat.py",line 33,再加工
2018-01-22 20:01:59,595:提高价值201-01-22 20:01:59,595:文件" fakepath / flask / app.py",1612行, 在full_dispatch_request
2018-01-22 20:01:59,595:rv = self.dispatch_request()
2018-01-22 20:01:59,596:文件 " fakepath / flask / app.py",第1598行,在dispatch_request2018-01-22 20:01:59,596:return self.view_functionsrule.endpoint
2018年1月22日 20:01:59,596:File" fakepath / flask_login / utils.py",第261行,in decorated_view
2018-01-22 20:01:59,596:return func(* args, ** kwargs)
2018-01-22 20:01:59,597:文件" /home/apoalphagammawebmaster/inventory/app/auth/views.py" ;,第248行, in add_reservation
2018-01-22 20:01:59,597:form = form, title =' Add Reservation')
2018-01-22 20:01:59,597:文件 " fakepath / flask / templating.py",第134行,在render_template2018-01-22 20:01:59,597:context,ctx.app)
2018-01-22 20:01:59,597:文件" fakepath / flask / templating.py",第116行,in _render
2018-01-22 20:01:59,597:rv = template.render(context)
2018-01-22 20:01:59,598:File " fakepath / jinja2 / asyncsupport.py",第76行,在渲染中2018-01-22 20:01:59,598:return original_render(self,* args,** kwargs)2018-01-22 20:01:59,598:File" fakepath / jinja2 / environment.py", 第1008行,在渲染中2018-01-22 20:01:59,598:返回 self.environment.handle_exception(exc_info,True)
2018-01-22 20:01:59,598:文件" fakepath / jinja2 / environment.py",第780行,在 handle_exception
2018-01-22 20:01:59,599:reraise(exc_type, exc_value,tb)
2018-01-22 20:01:59,599:文件 " fakepath / jinja2 / _compat.py",第37行,在重新加入中2018-01-22 20:01:59,599:提高value.with_traceback(tb)
2018-01-22 20:01:59,599:文件 " /home/apoalphagammawebmaster/inventory/app/templates/auth/reservations/reservation.html" ;, 第2行,在顶级模板代码中2018-01-22 20:01:59,599:
{%extends" base.html" %}
2018-01-22 20:01:59,599:文件 " /home/apoalphagammawebmaster/inventory/app/templates/base.html" ;, line 48,顶层模板代码
2018-01-22 20:01:59,600:{% 块体%} 2018-01-22 20:01:59,600:文件 " /home/apoalphagammawebmaster/inventory/app/templates/auth/reservations/reservation.html" ;, 第27行,在块#34; body"
2018-01-22 20:01:59,600:{{ wtf.quick_form(form)}} 2018-01-22 20:01:59,600:文件 " fakepath / jinja2 / runtime.py",第579行,在_invoke中2018-01-22 20:01:59,600:rv = self._func(* arguments)
2018-01-22 20:01:59,601:文件 " fakepath / flask_bootstrap / templates / bootstrap / wtf.html",第205行,在 模板
2018-01-22 20:01:59,601:{{form_field(field,2018-01-22 20:01:59,601:File" fakepath / jinja2 / runtime.py",line 579,在_invoke
2018-01-22 20:01:59,601:rv = self._func(* arguments)
2018-01-22 20:01:59,601:文件 " fakepath / flask_bootstrap / templates / bootstrap / wtf.html",第123行,在 模板
2018-01-22 20:01:59,601:
{{field(class =" form-control",** kwargs)| safe}}
2018-01-22 20:01:59,601:File" fakepath / wtforms / fields / core.py",第153行,in 致电
2018-01-22 20:01:59,601:return self.meta.render_field(self,kwargs)
2018-01-22 20:01:59,602:<登记/> 文件&#34; fakepath / wtforms / meta.py&#34;,第56行,在render_field2018-01-22 20:01:59,602:return field.widget(field, ** render_kw)
2018-01-22 20:01:59,602:文件&#34; fakepath / wtforms / widgets / core.py&#34;,第287行,致电 2018 -01-22 20:01:59,602:用于val,标签,选中 field.iter_choices():
2018-01-22 20:01:59,602:文件 &#34; fakepath / wtforms / ext / sqlalchemy / fields.py&#34;,第107行,in iter_choices
2018-01-22 20:01:59,602:for pk,obj in self._get_object_list():
2018-01-22 20:01:59,602:文件 &#34; fakepath / wtforms / ext / sqlalchemy / fields.py&#34;,第100行,in _get_object_list
2018-01-22 20:01:59,602:self._object_list = list((text_type(get_pk(obj)),obj)查询中的obj)
2018-01-22 20:01:59,603:File&#34; fakepath / wtforms / ext / sqlalchemy / fields.py&#34;,line 100,在中2018-01-22 20:01:59,603:self._object_list = list((text_type(get_pk(obj)),obj)for obj in query)
2018-01-22 20:01:59,603:File&#34; fakepath / wtforms / ext / sqlalchemy / fields.py& #34;,行 189,在get_pk_from_identity
2018-01-22 20:01:59,603:cls, key = identity_key(instance = obj)
2018-01-22 20:01:59,603: ValueError:解包的值太多(预期2)
答案 0 :(得分:7)
问题在github问题主题 - https://github.com/flask-admin/flask-admin/issues/1588
中有所涉及基本上,flask-admin
pip包已过时,就最新的sqlalchemy
pip包而言。在那个特定的领域,
cls, key = identity_key(instance=obj)
sqlalchemy
现在返回3个对象,但flask-admin
只期望2,因此错误。
真正的解决方案是等到新的flask-admin
版本上传到点,直到那时,你有几个选项。
fields.py
文件sqlalchemy
限制为版本1.2.0b3
。您可以在requirements.txt文件中执行此操作,也可以使用pip upgrade install pip install --upgrade sqlalchemy==1.2.0b3
flask-admin
主分支中,请安装flask-admin
的pip位置为git+https://github.com/flask-admin/flask-admin
的版本。pip install --upgrade git+https://github.com/flask-admin/flask-admin
。同样,您可以在requirements.txt文件中执行此操作,也可以使用pip upgrade install flask-admin
执行此操作。我个人的偏好,以及我所做的,是选项3.如果您仔细查看代码本身,那么维护人员想要删除它,以及它们如何处理使用它更好,一般来说,这些东西,我更喜欢前进(sqlalchemy
的最新版本),而不是把东西拿回来(回滚php artisan make:auth
到以前的版本),当然比手动更好编辑原始代码。
答案 1 :(得分:0)
我也遇到了这个问题。我可以使用这些技巧(如上所述),但是在https://github.com/wtforms/wtforms/issues/373和https://github.com/flask-admin/flask-admin/issues/1588的讨论中,看起来对wtforms_sqlalchemy的支持不如wtforms_alchemy。
所以,我安装了wtforms_alchemy
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.company.APP.common.mapping.orika.configuration.mappers.user.UserMapperTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected ma.glasnost.orika.MapperFacade com.company.APP.common.mapping.orika.configuration.mappers.BaseMapperTest.mapper; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mapperFacadeFactoryBean': FactoryBean threw exception on object creation; nested exception is ma.glasnost.orika.MappingException: java.lang.RuntimeException: java.io.IOException: invalid constant type: 15 at 142
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1204)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:385)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:82)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:212)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:199)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:251)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:253)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:216)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:82)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:60)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:67)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:162)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected ma.glasnost.orika.MapperFacade com.company.APP.common.mapping.orika.configuration.mappers.BaseMapperTest.mapper; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mapperFacadeFactoryBean': FactoryBean threw exception on object creation; nested exception is ma.glasnost.orika.MappingException: java.lang.RuntimeException: java.io.IOException: invalid constant type: 15 at 142
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:555)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 25 more
...
...
...
Caused by: java.io.IOException: invalid constant type: 15 at 142
at javassist.bytecode.ConstPool.readOne(ConstPool.java:1044)
at javassist.bytecode.ConstPool.read(ConstPool.java:984)
at javassist.bytecode.ConstPool.<init>(ConstPool.java:125)
at javassist.bytecode.ClassFile.read(ClassFile.java:770)
at javassist.bytecode.ClassFile.<init>(ClassFile.java:114)
at javassist.CtClassType.getClassFile2(CtClassType.java:191)
... 79 more
在我的项目中将wtforms_sqlalchemy替换为wtform_alchemy
pip install wtforms_alchemy
和我的项目工作相同。