Skip to content
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

Pre-populating the database #21

Open
Carelvd opened this issue Sep 20, 2019 · 2 comments
Open

Pre-populating the database #21

Carelvd opened this issue Sep 20, 2019 · 2 comments

Comments

@Carelvd
Copy link

Carelvd commented Sep 20, 2019

Dear Ms. Cochrane,

I am trying to use your package with Sandman 2 and I was wondering if you were aware of any examples that use both packages ? I was wondering if there were any examples using the client fixture from pytest-flask and db_session or db_engine from your package.

Extending the example from the documentation I am pre-populate an empty database as below :

@pytest.fixture()
def session(db_session):
    db_session.add(Table(id=0, name="test"))
    db_session.commit() # This triggers an error
    return db_session

def test_FUNCTION(client, session):
    client.post(/some/path/, data={"name":"testing"})
    record = session.query(Table).get(1)
    assert record.name == "testing"

I find that either the rollback mechanism is failing with the pymssql driver at the line with the commit.

Table 'table' does not have the identity property. Cannot perform SET operation.DB-Lib error message 20018, severity 16:\nGeneral SQL Server error: Check messages from the SQL Server\n

I was hoping you may have come across this before and might be able to provide me with the odd pointer, the full code is available through a testing branch; explained in issue #22.

Regards,

Carel van Dam

@Carelvd Carelvd changed the title fixtures pre-populating the database Pre-populating the database Sep 20, 2019
@Carelvd
Copy link
Author

Carelvd commented Sep 23, 2019

The initial error was due to the create statement for the table in SQL; I hadn't set an index upon the table, Doing so resolved my original issue now I find that SQLAlchemy errors out as follows :

sqlalchemy.exc.InvalidRequestError: Object '<Table at 0x4c4a0f0>' is already attached to session '2' (this is '3')

The client also seems to hang in some scenarios when I try to GET/POST data. I also went through the other issues and Issues #12, #19 and #7 appear similar in nature to what I am trying.

@jeancochrane
Copy link
Owner

Very strange. The first thing I'd want to rule out is some kind of SQL Server incompatibility. Seems like you worked on testing multiple database engines in #22 -- were you able to reproduce the most recent error in Postgres?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants