def test_transaction_error(): """Database connections are cleaned up regardless of in-transaction query errors. """ aggregate_config = [{ 'prefix': 'aprefix', 'aggregates': [ { 'quantity': 'quantity_one', 'metrics': ['sum'], 'imputation': { 'sum': { 'type': 'constant', 'value': 137 }, 'count': { 'type': 'zero' } } }, ], 'groups': ['entity_id'], 'intervals': ['all'], 'knowledge_date_column': 'knowledge_date', 'from_obj': 'data' }] with testing.postgresql.Postgresql() as postgresql: engine = create_engine(postgresql.url()) setup_db(engine) feature_generator = FeatureGenerator(db_engine=engine, features_schema_name='features') with pytest.raises(sqlalchemy.exc.ProgrammingError): feature_generator.create_all_tables( feature_dates=['2013-09-30', '2014-09-30'], feature_aggregation_config=aggregate_config, state_table='statez', # WRONG! ) (query_count, ) = engine.execute('''\ select count(*) from pg_stat_activity where query not ilike '%%pg_stat_activity%%' ''').fetchone() assert query_count == 0 engine.dispose()
def test_transaction_error(test_engine): """Database connections are cleaned up regardless of in-transaction query errors. """ aggregate_config = [{ "prefix": "aprefix", "aggregates": [{ "quantity": "quantity_one", "metrics": ["sum"], "imputation": { "sum": { "type": "constant", "value": 137 }, "count": { "type": "zero" }, }, }], "groups": ["entity_id"], "intervals": ["all"], "knowledge_date_column": "knowledge_date", "from_obj": "data", }] feature_generator = FeatureGenerator( db_engine=test_engine, features_schema_name="features", ) with pytest.raises(sqlalchemy.exc.ProgrammingError): feature_generator.create_all_tables( feature_dates=["2013-09-30", "2014-09-30"], feature_aggregation_config=aggregate_config, state_table="statez", # WRONG! ) ((query_count, ), ) = test_engine.execute( t("""\ select count(1) from pg_stat_activity where datname = :datname and query not ilike '%%pg_stat_activity%%' """), datname=test_engine.url.database, ) assert query_count == 0