Have you tried pdb?

On Fri, Nov 18, 2011 at 9:32 AM, Tom Evans <tevans...@googlemail.com> wrote:
> On Fri, Nov 18, 2011 at 1:25 PM, Kayode Odeyemi <drey...@gmail.com> wrote:
>> On Fri, Nov 18, 2011 at 12:04 PM, Tom Evans <tevans...@googlemail.com>
>> wrote:
>>>
>>> On Fri, Nov 18, 2011 at 8:20 AM, Kayode Odeyemi <drey...@gmail.com> wrote:
>>> > Hello friends,
>>> >
>>> > I'm having a deep Django-MySQLDB error and I'm doing some debugging to
>>> > trace exactly where the problem is. It seems to me that this is very
>>> > related
>>> > to MySQLDB
>>> > cursor implementaton.
>>> >
>>> > What I want to do is to run the raw sql from the interactive mode like
>>> > this:
>>> >
>>> > import MySQLdb
>>> > db=MySQLdb.connect(passwd="pass",db="dname")
>>> > c=db.cursor()
>>> > max_price=5
>>> > c.execute(RAW_SQL_HERE)
>>> >
>>> > In case you don't mind, here is the full stack trace:
>>> >
>>> > Traceback (most recent call last):
>>> > File
>>> >
>>> > "C:\Python27\lib\site-packages\celery-2.3.2-py2.7.egg\celery\execute\trace.py"
>>> > , line 36, in trace
>>> > return cls(states.SUCCESS, retval=fun(*args, **kwargs))
>>> > File
>>> >
>>> > "C:\Python27\lib\site-packages\celery-2.3.2-py2.7.egg\celery\app\task\__init__
>>> > .py", line 232, in __call__
>>> > return self.run(*args, **kwargs)
>>> > File
>>> >
>>> > "C:\Python27\lib\site-packages\celery-2.3.2-py2.7.egg\celery\app\__init__.py",
>>> > line 172, in run
>>> > return fun(*args, **kwargs)
>>> > File
>>> >
>>> > "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\db\transaction.py",
>>> > line 217, in inner
>>> > res = func(*args, **kwargs)
>>> > File "api\tasks.py", line 146, in queue_transaction
>>> > txn.save()
>>> > File
>>> >
>>> > "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\db\models\base.py",
>>> > line 460, in save
>>> > self.save_base(using=using, force_insert=force_insert,
>>> > force_update=force_update)
>>> >
>>> > File
>>> >
>>> > "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\db\models\base.py",
>>> > line 570, in save_base
>>> > created=(not record_exists), raw=raw, using=using)
>>> > File
>>> >
>>> > "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\dispatch\dispatcher
>>> > .py", line 172, in send
>>> > response = receiver(signal=self, sender=sender, **named)
>>> > File
>>> >
>>> > "C:\Python27\lib\site-packages\django_audit_log-0.2.2-py2.7.egg\audit_log\mode
>>> > ls\managers.py", line 64, in post_save
>>> > self.create_log_entry(instance, created and 'I' or 'U')
>>> > File
>>> >
>>> > "C:\Python27\lib\site-packages\django_audit_log-0.2.2-py2.7.egg\audit_log\mode
>>> > ls\managers.py", line 61, in create_log_entry
>>> > manager.create(action_type = action_type, **attrs)
>>> > File
>>> >
>>> > "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\db\models\manager.p
>>> > y", line 138, in create
>>> > return self.get_query_set().create(**kwargs)
>>> > File
>>> >
>>> > "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\db\models\query.py"
>>> > , line 360, in create
>>> > obj.save(force_insert=True, using=self.db)
>>> > File
>>> >
>>> > "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\db\models\base.py",
>>> > line 460, in save
>>> > self.save_base(using=using, force_insert=force_insert,
>>> > force_update=force_update)
>>> >
>>> > File
>>> >
>>> > "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\db\models\base.py",
>>> > line 553, in save_base
>>> > result = manager._insert(values, return_id=update_pk, using=using)
>>> > File
>>> >
>>> > "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\db\models\manager.p
>>> > y", line 195, in _insert
>>> > return insert_query(self.model, values, **kwargs)
>>> > File
>>> >
>>> > "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\db\models\query.py"
>>> > , line 1436, in insert_query
>>> > return query.get_compiler(using=using).execute_sql(return_id)
>>> > File
>>> >
>>> > "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\db\models\sql\compi
>>> > ler.py", line 791, in execute_sql
>>> > cursor = super(SQLInsertCompiler, self).execute_sql(None)
>>> > File
>>> >
>>> > "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\db\models\sql\compi
>>> > ler.py", line 735, in execute_sql
>>> > cursor.execute(sql, params)
>>> > File
>>> >
>>> > "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\db\backends\util.py
>>> > ", line 34, in execute
>>> > return self.cursor.execute(sql, params)
>>> > File
>>> >
>>> > "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\db\backends\mysql\b
>>> > ase.py", line 86, in execute
>>> > return self.cursor.execute(query, args)
>>> > File "build\bdist.win32\egg\MySQLdb\cursors.py", line 176, in execute
>>> > if not self._defer_warnings: self._warning_check()
>>> > File "build\bdist.win32\egg\MySQLdb\cursors.py", line 92, in
>>> > _warning_check
>>> > warn(w[-1], self.Warning, 3)
>>> > Warning: Data truncated for column 'jno' at row 1
>>> > None
>>> >
>>> >
>>> > Some of the solutions I found on the internet such as changing teh
>>> > default
>>> > character set
>>> > to utf8 has been done. I also consulted MySQL doc ref by changing the
>>> > sql_mode to
>>> > TRADITIONA both at session and global level, as well as in settings.py.
>>> > Still no luck.
>>> >
>>> > Please how do I get the raw SQL executed by Django?
>>> >
>>> > Any help will be appreciated.
>>> >
>>>
>>> Your SQL query, which you didn't show, is inserting data into a DB
>>> table, whose definition you didn't show. The data it is inserting in,
>>> which you didn't show, is getting truncated in the 'jno' column.
>>
>> Why this is getting truncated I don't know because the field has a length of
>> 50 and the value I'm trying to store is 01234SS. So I just concluded that
>> the data I'm trying to insert in not the problem here neither it is the
>> table structure.
>>
>
> I don't know why; you still haven't shown your DB table, data, query...
>
> Strange conclusion btw.
>
>>>
>>> This
>>> is raised as an exception, since you set sql_mode to TRADITIONAL
>>
>> Before setting the sql_mode to TRADITIONAL, it was at its default state, and
>> it still got the warnings as error.
>>
>>>
>>> and/or run in DEBUG mode, which makes django configure
>>> Database.Warning as errors.
>>
>> Does this mean that if I'm not running Django in DEBUG mode, the record will
>> still be inserted ignoring the warnings?
>
> Yes, the warning is still generated, but it is suppressed and no
> exception will be raised, unless you are running in TRADITIONAL mode.
>
>>>
>>> Django doesn't execute the query, you are executing it on the raw DB
>>> cursor, so it will not be logged (certainly not by DDT).
>>
>> Actually I just want to put some debug trace in Django source and re-compile
>> so I can see the raw sql. Isn't this possible? (Already considering
>> django-debug-toolbar)
>
> DDT reports the queries that are logged by django's ORM. This query is
> not made by Django's ORM. Therefore, it will not be logged by DDT.
>
> Django is not making the query, you are, using a py-mysqldb cursor.
> Therefore to log it in more detail than what you already know - you
> are passing the query and the arguments - you would need to look into
> py-mysqldb.
>
> Tom
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to