Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLAlchemy Session.add doesn't work?
    primarykey
    data
    text
    <p>I have a strange error using Python 3.3.0 and SQLAlchemy 0.8.0:</p> <pre><code>from sqlalchemy import create_engine, Integer, String, Text, Column, Sequence, DateTime, ForeignKey from sqlalchemy.orm import sessionmaker, relationship, backref from sqlalchemy.ext.declarative import declarative_base engine = create_engine("sqlite:///:memory:", echo=True) Session = sessionmaker(bind = engine) Base = declarative_base() class Product(Base): __tablename__ = "products" id = Column(Integer, primary_key=True) name = Column(String(200)) description = Column(Text) Base.metadata.create_all(engine) session = Session() product = Product() product.id = 1 product.name = "Test" product.description = "Test" session.add(product) print(product in session) # Expected true session.commit() print(session.query(Product).all()) # Expected the previous item </code></pre> <p>As commented in code I expected the add method to add the product to the database using an INSERT. But it doesn't nor does it throw an exception. This is the log:</p> <pre><code>2013-04-16 18:03:14,368 INFO sqlalchemy.engine.base.Engine PRAGMA table_info("products") 2013-04-16 18:03:14,369 INFO sqlalchemy.engine.base.Engine () 2013-04-16 18:03:14,371 INFO sqlalchemy.engine.base.Engine CREATE TABLE products ( id INTEGER NOT NULL, name VARCHAR(200), description TEXT, PRIMARY KEY (id) ) 2013-04-16 18:03:14,371 INFO sqlalchemy.engine.base.Engine () 2013-04-16 18:03:14,371 INFO sqlalchemy.engine.base.Engine COMMIT False 2013-04-16 18:04:04,706 INFO sqlalchemy.engine.base.Engine BEGIN (implicit) 2013-04-16 18:04:04,708 INFO sqlalchemy.engine.base.Engine SELECT products.id AS products_id, products.name AS products_name, products.description AS products_description FROM products 2013-04-16 18:04:04,709 INFO sqlalchemy.engine.base.Engine () [] </code></pre> <p>I already tried several things: </p> <ul> <li>Changing the engine doesn't work. I also tried postgresql. </li> <li>I tried debugging. When I reach the body of the add method there is nothing to step into.</li> </ul> <p>Am I doing something wrong or is this a bug?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload