Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
318 views
in Technique[技术] by (71.8m points)

python - How to debug: Internal Error current transaction is aborted, commands ignored until end of transaction block

Hi Stackoverflow people,

I do my first steps with GeoDjango and I am looking for better options to check faulty sql statements.

So far, I simply wanted to safe a lng+lat point in my postgresql table.

The model is defined with:

    geolocation = models.PointField(_('Geo Location'), 
                geography=True, 
                null = True, 
                blank = True,
                help_text=_('Geolocation with Longitude and Latitude'))

    objects = models.GeoManager()

In my view, I try to execute the following command

savedProject.geolocation = GEOSGeometry('POINT(%s %s)' %(u_lng,u_lat))

but I receive the following error when I try to save the form:

Exception Type: InternalError Exception Value: current transaction is aborted, commands ignored until end of transaction block

What is the reason for this error? I believe that there could be something wrong with the sql statement, but what is the best way to check? Django just provides with general error message "Internal Error".

Thank you for your help and suggestions!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In most cases this means that the previous SQL statement failed to execute. In this case you should:

  1. Enable SQL logging, see the following snippet to paste in settings.py

  2. Set DEBUG=1, or SQL won't be logged

  3. Run runserver again, and you should see all SQL queries in the console

  4. Execute the last SQL queries directly in your database, you should then find which queries fail and then you should be able to debug them - or open a new question which is specific to the query that causes the problem. You can use phpMyAdmin, or directly a CLI client, or whatever database client, to execute the SQL queries one by one until you find the one that needs some love.

SQL Logging configuration:

LOGGING = { 
   'version': 1,
   'disable_existing_loggers': True,
   'formatters': {
       'simple': {
           'format': '%(levelname)s %(message)s',
       },  
   },  
   'handlers': {
       'console':{
           'level':'DEBUG',
           'class':'logging.StreamHandler',
           'formatter': 'simple'
       },  
   },  
   'loggers': {
       'django': {
           'handlers': ['console'],
           'level': 'DEBUG',
       },  
   }   
}

If this configuration does not provide any additional console output with runserver, then feel free to try django-autocomplete-light's example test_project:

  1. Read and paste the installation commands in /tmp

  2. Change dir to autocomplete_light_env/src/django-autocomplete-light/test_project

  3. Open test_project/settings.py, replace the LOGGING configuration by the one above

  4. Runserver and open your browser

Your console will look like:

Validating models...

0 errors found
Django version 1.4.1, using settings 'test_project.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
DEBUG (0.001) SELECT "django_content_type"."id", "django_content_type"."name", "django_content_type"."app_label", "django_content_type"."model" FROM "django_content_type" WHERE ("django_content_type"."model" = taggable  AND "django_content_type"."app_label" = charfield_autocomplete ); args=('taggable', 'charfield_autocomplete')
DEBUG (0.000) 
        SELECT DISTINCT "tagging_tag".id, "tagging_tag".name
        FROM
            "tagging_tag"
            INNER JOIN "tagging_taggeditem"
                ON "tagging_tag".id = "tagging_taggeditem".tag_id
            INNER JOIN "charfield_autocomplete_taggable"
                ON "tagging_taggeditem".object_id = "charfield_autocomplete_taggable"."id"

        WHERE "tagging_taggeditem".content_type_id = 11

        GROUP BY "tagging_tag".id, "tagging_tag".name

        ORDER BY "tagging_tag".name ASC; args=[]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...