maxtepkeev / architect

A set of tools which enhances ORMs written in Python with more features
Other
391 stars 57 forks source link

Missing format keys #13

Closed clearclaw closed 9 years ago

clearclaw commented 9 years ago

The current release on PyPi (0.5.0) has the following code in architect/databases/mysql/partition.py:

class Partition(BasePartition):
    def prepare(self):
        """
        Prepares table for partitioning by reconstructing table's primary key.
        """
        if self.column_name not in self.pks:
            self.database.execute("""
                ALTER TABLE {parent_table} DROP PRIMARY KEY, ADD PRIMARY KEY ({pk}, {column});
            """.format(pk=', '.join(pk for pk in self.pks), parent_table=self.table, column=self.column_name))

        return self.database.execute("""
            DROP PROCEDURE IF EXISTS {parent_table}_create_partition;

            DELIMITER $$
            CREATE PROCEDURE {parent_table}_create_partition(IN column_value VARCHAR(255))
            BEGIN
                DECLARE
                    tablename VARCHAR(255);
                    columntype VARCHAR(30);
                    {declarations}

                {common_variables}

                IF NOT EXISTS(
                    SELECT 1 FROM information_schema.partitions
                    WHERE table_name='{parent_table}' AND partition_name=tablename})
                THEN
                    SELECT data_type INTO columntype
                    FROM information_schema.columns
                    WHERE table_name = '{parent_table}' AND column_name = '{column}';

                    {creation_variables}

                    SET @sql := CONCAT(
                        'ALTER TABLE {parent_table} ADD PARTITION ('
                            {checks}
                        ');'
                    );

                    PREPARE stmt FROM @sql;
                    EXECUTE stmt;
                    DEALLOCATE PREPARE stmt;
                END IF;
            END $$
            DELIMITER ;
        """.format(parent_table=self.table))

As expected, it blows up with missing keys on the .format().

maxtepkeev commented 9 years ago

Thanks for reporting this, v0.5.1 with the fix is on PyPI.

This code is from one of the future versions of Architect (I'm in the process of MySQL refactoring) and it found it's way to the PyPI release by mistake because I forgot to do a git stash ;-(

Sorry for this.