Hello Djangonauts,

I've found an issue with initial data and SQLite - if any of the fields
in the initial data has a "%" in it, the import fails. Pysqlite is
apparently processing the query for string formatting args.

Now, I'm *not* getting this error on MySQLdb, but haven't tested
postgres/ado_mssql etc. From [1] I think postgres is also affected, and
would be interested if someone could check this out.

It seems to be quite easy to fix - just do a search and replace for %
to %% around line 352 in django/core/management.py, in
get_sql_initial_data_for_model(). However, I'm not sure what the best
practice for doing RDBMS specific "tweaking/fixing" is - should this be
implemented in something like db/backends/<db>/base.py?

Nor am I sure how far you want to go in fixing what appears to be a
pysqlite implementation, uh, wart.

Here's a test which should show this up:


/format_string/test/models.py
---------------------------------------

from django.db import models

class Simple(models.Model):
    name = models.CharField(maxlength = 50)

__test__ = {'API_TESTS':"""
    # Regression test for #
    # Check that the format string fix stores the correct number of %'s


    >>> Simple.objects.get(pk=1).name
    'a%a'
    >>> Simple.objects.get(pk=2).name
    'a%%a'
    >>> Simple.objects.get(pk=3).name
    'a%%%a'
    >>> Simple.objects.get(pk=4).name
    'a%%a%%a'
    >>> Simple.objects.get(pk=5).name
    'a%%%a%%%a'
    """
}


/format_string/test/sql/simple.sql
--------------------------------------------
INSERT INTO initial_sql_formatstring_regress_simple (name) VALUES
('a%a');
INSERT INTO initial_sql_formatstring_regress_simple (name) VALUES
('a%%a');
INSERT INTO initial_sql_formatstring_regress_simple (name) VALUES
('a%%%a');
INSERT INTO initial_sql_formatstring_regress_simple (name) VALUES
('a%%a%%a');
INSERT INTO initial_sql_formatstring_regress_simple (name) VALUES
('a%%%a%%%a');



---------------------------------------------

So - as it is, this will fail on SQLite at the .get()'s as the initial
sql import will choke when it can't work out what %a is.

Cheers,
Simon G.



[1]
http://groups.google.com/group/django-developers/browse_thread/thread/14d1bdf73085f02b/ae5dfd2b30194d4a%23ae5dfd2b30194d4a


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---

Reply via email to