Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7734273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:12:31+00:00 2026-06-01T07:12:31+00:00

I am using pdb (actually ipdb ) to debug my Django models.py . In

  • 0

I am using pdb (actually ipdb) to debug my Django models.py. In particular I am trying to debug these lines of code:

def add_can_view( sender, **kwargs ) :
    #import ipdb; ipdb.set_trace()
    for content_type in ContentType.objects.all():
        Permission.objects.create(
            content_type = content_type,
            codename     = 'view_{}'.format( content_type.model ),
            name         = 'Can view {}'.format( content_type.name )
        )

post_syncdb.connect( add_can_view )

The code above, which was provided in this question, has an IntegrityError error when I run python manage.py syncdb:

ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (11, 0))
---------------------------------------------------------------------------
IntegrityError                            Traceback (most recent call last)
/Users/hobbes3/.virtualenvs/doors/lib/python2.7/site-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
    173             else:
    174                 filename = fname
--> 175             __builtin__.execfile(filename, *where)

/Users/hobbes3/Sites/mysite/manage.py in <module>()
      8     from django.core.management import execute_from_command_line
      9 
---> 10     execute_from_command_line(sys.argv)

/Users/hobbes3/.virtualenvs/doors/lib/python2.7/site-packages/django/core/management/__init__.pyc in execute_from_command_line(argv)
    441     """
    442     utility = ManagementUtility(argv)
--> 443     utility.execute()
    444 
    445 def execute_manager(settings_mod, argv=None):

/Users/hobbes3/.virtualenvs/doors/lib/python2.7/site-packages/django/core/management/__init__.pyc in execute(self)
    380             sys.stdout.write(self.main_help_text() + '\n')
    381         else:
--> 382             self.fetch_command(subcommand).run_from_argv(self.argv)
    383 
    384 def setup_environ(settings_mod, original_settings_path=None):

/Users/hobbes3/.virtualenvs/doors/lib/python2.7/site-packages/django/core/management/base.pyc in run_from_argv(self, argv)
    194         options, args = parser.parse_args(argv[2:])
    195         handle_default_options(options)
--> 196         self.execute(*args, **options.__dict__)
    197 
    198     def execute(self, *args, **options):

/Users/hobbes3/.virtualenvs/doors/lib/python2.7/site-packages/django/core/management/base.pyc in execute(self, *args, **options)
    230             if self.requires_model_validation:
    231                 self.validate()
--> 232             output = self.handle(*args, **options)
    233             if output:
    234                 if self.output_transaction:

/Users/hobbes3/.virtualenvs/doors/lib/python2.7/site-packages/django/core/management/base.pyc in handle(self, *args, **options)
    369         if args:
    370             raise CommandError("Command doesn't accept any arguments")
--> 371         return self.handle_noargs(**options)
    372 
    373     def handle_noargs(self, **options):

/Users/hobbes3/.virtualenvs/doors/lib/python2.7/site-packages/South-0.7.4-py2.7.egg/south/management/commands/syncdb.pyc in handle_noargs(self, migrate_all, **options)
     88 
     89         # OK, run the actual syncdb

---> 90         syncdb.Command().execute(**options)
     91 
     92         settings.INSTALLED_APPS = old_installed

/Users/hobbes3/.virtualenvs/doors/lib/python2.7/site-packages/django/core/management/base.pyc in execute(self, *args, **options)
    230             if self.requires_model_validation:
    231                 self.validate()
--> 232             output = self.handle(*args, **options)
    233             if output:
    234                 if self.output_transaction:

/Users/hobbes3/.virtualenvs/doors/lib/python2.7/site-packages/django/core/management/base.pyc in handle(self, *args, **options)
    369         if args:
    370             raise CommandError("Command doesn't accept any arguments")
--> 371         return self.handle_noargs(**options)
    372 
    373     def handle_noargs(self, **options):

/Users/hobbes3/.virtualenvs/doors/lib/python2.7/site-packages/django/core/management/commands/syncdb.pyc in handle_noargs(self, **options)
    108         # Send the post_syncdb signal, so individual apps can do whatever they need

    109         # to do at this point.

--> 110         emit_post_sync_signal(created_models, verbosity, interactive, db)
    111 
    112         # The connection may have been closed by a syncdb handler.


/Users/hobbes3/.virtualenvs/doors/lib/python2.7/site-packages/django/core/management/sql.pyc in emit_post_sync_signal(created_models, verbosity, interactive, db)
    187         models.signals.post_syncdb.send(sender=app, app=app,
    188             created_models=created_models, verbosity=verbosity,
--> 189             interactive=interactive, db=db)

/Users/hobbes3/.virtualenvs/doors/lib/python2.7/site-packages/django/dispatch/dispatcher.pyc in send(self, sender, **named)
    170 
    171         for receiver in self._live_receivers(_make_id(sender)):
--> 172             response = receiver(signal=self, sender=sender, **named)
    173             responses.append((receiver, response))
    174         return responses

/Users/hobbes3/Sites/mysite/doors/signals.py in add_can_view(sender, **kwargs)
      8             content_type = content_type,
      9             codename     = 'view_{}'.format( content_type.model ),
---> 10             name         = 'Can view {}'.format( content_type.name )
     11         )
     12 

/Users/hobbes3/.virtualenvs/doors/lib/python2.7/site-packages/django/db/models/manager.pyc in create(self, **kwargs)
    135 
    136     def create(self, **kwargs):
--> 137         return self.get_query_set().create(**kwargs)
    138 
    139     def bulk_create(self, *args, **kwargs):

/Users/hobbes3/.virtualenvs/doors/lib/python2.7/site-packages/django/db/models/query.pyc in create(self, **kwargs)
    375         obj = self.model(**kwargs)
    376         self._for_write = True
--> 377         obj.save(force_insert=True, using=self.db)
    378         return obj
    379 

/Users/hobbes3/.virtualenvs/doors/lib/python2.7/site-packages/django/db/models/base.pyc in save(self, force_insert, force_update, using)
    461         if force_insert and force_update:
    462             raise ValueError("Cannot force both insert and updating in model saving.")
--> 463         self.save_base(using=using, force_insert=force_insert, force_update=force_update)
    464 
    465     save.alters_data = True

/Users/hobbes3/.virtualenvs/doors/lib/python2.7/site-packages/django/db/models/base.pyc in save_base(self, raw, cls, origin, force_insert, force_update, using)
    549 
    550                 update_pk = bool(meta.has_auto_field and not pk_set)
--> 551                 result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
    552 
    553                 if update_pk:

/Users/hobbes3/.virtualenvs/doors/lib/python2.7/site-packages/django/db/models/manager.pyc in _insert(self, objs, fields, **kwargs)
    201 
    202     def _insert(self, objs, fields, **kwargs):
--> 203         return insert_query(self.model, objs, fields, **kwargs)
    204 
    205     def _update(self, values, **kwargs):

/Users/hobbes3/.virtualenvs/doors/lib/python2.7/site-packages/django/db/models/query.pyc in insert_query(model, objs, fields, return_id, raw, using)
   1574     query = sql.InsertQuery(model)
   1575     query.insert_values(fields, objs, raw=raw)
-> 1576     return query.get_compiler(using=using).execute_sql(return_id)
   1577 
   1578 

/Users/hobbes3/.virtualenvs/doors/lib/python2.7/site-packages/django/db/models/sql/compiler.pyc in execute_sql(self, return_id)
    908         cursor = self.connection.cursor()
    909         for sql, params in self.as_sql():
--> 910             cursor.execute(sql, params)
    911         if not (return_id and cursor):
    912             return

/Users/hobbes3/.virtualenvs/doors/lib/python2.7/site-packages/django/db/backends/util.pyc in execute(self, sql, params)
     38         start = time()
     39         try:
---> 40             return self.cursor.execute(sql, params)
     41         finally:
     42             stop = time()

/Users/hobbes3/.virtualenvs/doors/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.pyc in execute(self, query, args)
     50     def execute(self, query, args=None):
     51         try:
---> 52             return self.cursor.execute(query, args)
     53         except Database.IntegrityError, e:
     54             raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]

IntegrityError: duplicate key value violates unique constraint "auth_permission_content_type_id_codename_key"
DETAIL:  Key (content_type_id, codename)=(2, view_group) already exists.

I have a feeling that somehow there is a duplicate content_type and the error occurs when I try to apply the permission twice to content_type_id 2, which is auth.group. So when after I uncomment the import ipdb line, I want to check out some objects such as content_type, but if I type that, then all I get is <ContentType: content type>.

I know I can simply go look at the documentation to see the model, but how would you get a list of fields and methods without knowing what the class is?

Also bonus points for solving this error lol.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:12:33+00:00Added an answer on June 1, 2026 at 7:12 am

    Use dir (e.g. dir(content_type)) to get a list of attributes (including methods).

    In relation to django models, there is also a lot of information inside the _meta property. Explore that with dir(my_model_object._meta).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using LINQ on collections, what is the difference between the following lines of code?
I'm using Aptana Studio with Pydev 1.5.3 to debug my Django applications. I use
I'm using pdb to debug Python programs and am unhappy with it's behaviour. I
I am using python 2.4 and trying to debug a twisted application. Is there
I'm developing a django app using aquamacs as my ide. Pdb isn't working since
I'm using the following code to build and hierarchical cluster: dat <- read.table(textConnection( pdb
I am debugging some python code in emacs using pdb and getting some import
I am using pdb to examine a script having called run -d in an
How can I skip over a loop using pdb.set_trace() ? For example, pdb.set_trace() for
func(a(), b.c) When executing the line above in the pdb debugger, using step will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.