小编jus*_*anr的帖子

使用Flask-SQLAlchemy"陈旧关联代理,父对象已超出范围"

我以前从未遇到过这个错误:

sqlalchemy.exc.InvalidRequestError: stale association proxy, parent object has gone out of scope

在进行一些研究之后,它看起来像是因为父对象在关联代理工作时被垃圾收集.太棒了.

但是,我不确定它在哪里发生.

相关代码:

# models.py

class Artist(db.Model):
    # ...
    tags = association_proxy('_tags', 'tag', 
        creator=lambda t: ArtistTag(tag=t))
    # ...

class Tag(db.Model):
    # ...
    artist = association_proxy('_artists', 'artist', 
        creator=lambda a: ArtistTag(artist=a))
    # ...

class ArtistTag(db.Model):
    # ...
    artist_id = db.Column(db.Integer, ForeignKey('artists.id'))
    artist = db.relationship('Artist', backref='_tags')
    tag_id = db.Column(db.Integer, ForeignKey('tags.id'))
    tag = db.relationship('Tag', backref='_artists')

# api/tag.py
from flask.ext.restful import Resource
from ..
class ListArtistTag(Resource):
    def get(self, id):
        # much …
Run Code Online (Sandbox Code Playgroud)

python sqlalchemy flask flask-sqlalchemy

6
推荐指数
1
解决办法
785
查看次数

pytest.mark.parameterize没有"找到"灯具

我正在为一个小型库编写测试,并且在听了很多关于它的好事之后我决定使用py.test.

但是,pytest.mark.parameterize给我一些问题.起初,我想也许我只是错了一些parens而且它在其他地方寻找固定装置.所以我决定从给定的参数化示例开始:

@pytest.mark.parametrize("input,expected", [
    ("3+5", 8),
    ("2+4", 6),
    ("6*9", 42),
])
def test_eval(input, expected):
    assert eval(input) == expected
Run Code Online (Sandbox Code Playgroud)

但这会产生同样的错误:

夹具'输入'未找到

可用的灯具:capfd,pytestconfig,recwarn,capsys,tmpdir,monkeypatch

使用'py.test --fixtures [testpath]'获取有关它们的帮助.

我去谷歌搜索,但我找不到任何适用的答案.关于如何处理这个的任何想法?

编辑:我想知道哪些Python/py.test版本是有用的.

Python 3.4.0和py.test 2.6.4

python pytest

2
推荐指数
2
解决办法
1176
查看次数

标签 统计

python ×2

flask ×1

flask-sqlalchemy ×1

pytest ×1

sqlalchemy ×1