Pony ORM Release 0.5rc1

  • Before this release Pony used the exact letter case of an entity for the MySQL database table names (unless you specify the table name explicitly using the _table_ option).
    This approach turned out to be not reliable on all platforms: “MySQL table names are case-sensitive depending on the filesystem of the server. Since Windows and Mac are a case-insensitive OS, and Linux is case-sensitive; the MySQL database treats the uppercase table name differently than lowercase table name on Linux machines.”

    The official MySQL documentation reads:
    To avoid problems caused by such differences, it is best to adopt a consistent convention, such as always creating and referring to databases and tables using lowercase names. This convention is recommended for maximum portability and ease of use. Following this recommendation, starting with this release, Pony converts all the table names during its creation in accordance with the style of the respective database system. In MySQL and PostgreSQL Pony converts the table names to the lower case. In Oracle – to the upper case. In SQLite there is no need to convert the letter case – SQLite works with the table name letter case equally on all platforms.In order to make the new release compatible with your tables created with the previous Pony releases you have a couple of options:

    • Specify the table names for each entity explicitly:
          class MyEntity(db.Entity):
              _table_ = "MyEnity"
              ...
      
    • Convert the names of your tables to the lower case using SQL commands manually:
          RENAME TABLE `MyEntity` TO `myentity`
      
  • Starting with this release the names of tables, indexes and constraints in the database creation script are sorted in the alphabetical order.
  • Now you can use lambdas instead of parenthesis for the entities which are declared later in your code:
        class User(db.Entity):
            name = Required(unicode)
            photos = Set(lambda: Photo)
    
        class Photo(db.Entity):
            content = Required(buffer)
            user = Required(User)
    

    This can be useful if you want your IDE to check the names of declared entities and highlight typos.

  • Instances now have the before_insert, before_update, before_delete hooks:
        class MyEntity(db.Entity):
            ...
            def before_insert(self):
                print '%s is about to be inserted!' % self
            def before_update(self):
                print '%s is about to be updated!' % self
            def before_delete(self):
                print '%s is about to be deleted!' % self
    
  • Now options.MAX_FETCH_COUNT is set to None by default. Before this release Pony would throw the TooManyRowsFound exception if the number of instances returned by a query exceeds the MAX_FETCH_COUNT. Since this parameter can vary greatly, Pony doesn’t set it by default anymore.
  • We have added the concat() function and now you can do the following:
        
    select(concat(s.name, ':', s.dob.year, ':', s.scholarship) 
           for s in Student)
    
  • With the new Pony release you have the read-only access to the entity instances outside of the db_session. Before this release any attempt to use an instance outside of the db_session would result in a TransactionRolledBack exception. Now you can get the attribute values, but if the attribute that you’re trying to access was not loaded, then you’ll get the DatabaseSessionIsOver exception. The same exception will be raised in case you want to change attribute values.
    We hope that this option will not be misused. Most of the time you want to use entity instances within the db_session. If you find yourself using the instances outside of the db_session often, you probably doing something strange.
  • Now when you create new instances you can use the value of the primary key instead of the object. This is how you created an instance of a Student before:
        student = Student(name='Student name', group=Group[123])
    

    and now you can pass a primary key of the Group object instead:

        student = Student(name='Student name', group=123)
    

    The same approach can be used for the get() method.

  • Now you can specify the sequence name for PrimaryKey attributes for Oracle databases using the keyword argument sequence_name='seq_name'
  • The bug #41 was fixed. Now you can use the same variable name in subsequent filters and it can have different values.
  • Numerous other bugs were fixed