New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQLAlchemy: factory boy populates wrong field types in trasaction #253
Comments
The possible root cause is used transaction, because if I change the class BaseTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.app = app
cls._ctx = cls.app.test_request_context()
cls._ctx.push()
@classmethod
def tearDownClass(cls):
db.session.remove()
db.engine.dispose()
def setUp(self):
self.client = self.app.test_client()
self._ctx = self.app.test_request_context()
self._ctx.push()
db.session.close()
db.drop_all()
db.create_all()
def tearDown(self):
db.session.close()
self._ctx.pop() Test will pass. But this approach is a much more slower. |
I am hitting something similar, I think it's either caused by Factory Boy binding to a different SQLAlchemy session/transaction than the one the test is in. Possibly Factory boy is actually in the same session, but flushes or commits the session under the covers which makes it impossible to roll it back. I'm still digging into it, but curious if you found anything more here... |
This might indeed be caused by the default "do-not-flush" behavior of factory_boy. The optional force-flush added in #262 could help you, would you mind trying with the current master? |
My underlying issue turned out to be something unrelated to FactoryBoy. @citizen-stig I was able to track down the underlying issue by setting |
@rbarrois I've tried with current master and
|
I've created a git repository for that, so you can check it on your own. |
@citizen-stig Link to the git repo? |
Looking at this now. Second attempt threw an error because I didn't have Postgres setup... best practice when creating standalone reproductions of errors is to use an in-memory SQLite database. It's the polite thing to do so that it's easier for us maintainers to spend time fixing bugs instead of configuring databases. Rather than taking the time to do this, I looked a bit deeper at your code. I think I understand the issue here--see my comments alongside your code:
Possibly this is a bug with SQLAlchemy. More likely it's intended behavior to support duck-typing alongside strict DB column typing. Closing, as this isn't an issue with FactoryBoy. |
For instance I have a following model:
I have a following factory for that model
And a following test
This test will fail with following error:
AssertionError: u'4242' != 4242
But will work if native SQLAlchemy model is created.
My environment: python 2.7, factory_boy==2.6.0, SQLAlchemy==1.0.9, Flask-SQLAlchemy==2.1
The text was updated successfully, but these errors were encountered: