Various errors in modeltests.custom_pk

Issue #82 wontfix
Jason Chen
created an issue

{{{

!python

====================================================================== FAIL: Doctest: modeltests.custom_pk.models.test.API_TESTS


Traceback (most recent call last): File "/usr/local/lib/python3.1/dist-packages/django/test/_doctest.py", line 2234, in runTest raise self.failureException(self.format_failure(new.getvalue())) AssertionError: Failed doctest test for modeltests.custom_pk.models.test.API_TESTS File "/home/jason/Desktop/workspace/django-3k/build/tests/modeltests/custom_pk/models.py", line unknown line number, in API_TESTS


File "/home/jason/Desktop/workspace/django-3k/build/tests/modeltests/custom_pk/models.py", line ?, in modeltests.custom_pk.models.test.API_TESTS Failed example: new_bar = Bar.objects.create() Exception raised: Traceback (most recent call last): File "/usr/local/lib/python3.1/dist-packages/django/test/_doctest.py", line 1307, in run compileflags, 1), test.globs) File "<doctest modeltests.custom_pk.models.test__.API_TESTS[36]>", line 1, in <module> new_bar = Bar.objects.create() File "/usr/local/lib/python3.1/dist-packages/django/db/models/manager.py", line 138, in create return self.get_query_set().create(**kwargs) File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 350, in create obj.save(force_insert=True, using=self.db) File "/usr/local/lib/python3.1/dist-packages/django/db/models/base.py", line 439, in save self.save_base(using=using, force_insert=force_insert, force_update=force_update) File "/usr/local/lib/python3.1/dist-packages/django/db/models/base.py", line 515, in save_base for f in meta.local_fields if not isinstance(f, AutoField)] File "/usr/local/lib/python3.1/dist-packages/django/db/models/base.py", line 515, in <listcomp> for f in meta.local_fields if not isinstance(f, AutoField)] File "/home/jason/Desktop/workspace/django-3k/build/tests/modeltests/custom_pk/fields.py", line 29, in pre_save value = MyWrapper(''.join(random.sample(string.lowercase, 10))) AttributeError: 'module' object has no attribute 'lowercase'


File "/home/jason/Desktop/workspace/django-3k/build/tests/modeltests/custom_pk/models.py", line ?, in modeltests.custom_pk.models.test.API_TESTS Failed example: new_foo = Foo.objects.create(bar=new_bar) Exception raised: Traceback (most recent call last): File "/usr/local/lib/python3.1/dist-packages/django/test/_doctest.py", line 1307, in run compileflags, 1), test.globs) File "<doctest modeltests.custom_pk.models.test__.API_TESTS[37]>", line 1, in <module> new_foo = Foo.objects.create(bar=new_bar) NameError: name 'new_bar' is not defined


File "/home/jason/Desktop/workspace/django-3k/build/tests/modeltests/custom_pk/models.py", line ?, in modeltests.custom_pk.models.test.API_TESTS Failed example: f = Foo.objects.get(bar=new_bar) Exception raised: Traceback (most recent call last): File "/usr/local/lib/python3.1/dist-packages/django/test/_doctest.py", line 1307, in run compileflags, 1), test.globs) File "<doctest modeltests.custom_pk.models.test__.API_TESTS[38]>", line 1, in <module> f = Foo.objects.get(bar=new_bar) NameError: name 'new_bar' is not defined


File "/home/jason/Desktop/workspace/django-3k/build/tests/modeltests/custom_pk/models.py", line ?, in modeltests.custom_pk.models.test.API_TESTS Failed example: f == new_foo Exception raised: Traceback (most recent call last): File "/usr/local/lib/python3.1/dist-packages/django/test/_doctest.py", line 1307, in run compileflags, 1), test.globs) File "<doctest modeltests.custom_pk.models.test__.API_TESTS[39]>", line 1, in <module> f == new_foo NameError: name 'f' is not defined


File "/home/jason/Desktop/workspace/django-3k/build/tests/modeltests/custom_pk/models.py", line ?, in modeltests.custom_pk.models.test.API_TESTS Failed example: f.bar == new_bar Exception raised: Traceback (most recent call last): File "/usr/local/lib/python3.1/dist-packages/django/test/_doctest.py", line 1307, in run compileflags, 1), test.globs) File "<doctest modeltests.custom_pk.models.test__.API_TESTS[40]>", line 1, in <module> f.bar == new_bar NameError: name 'f' is not defined

}}}

Comments (3)

  1. Jason Chen reporter

    In Python3.1, the string function lowercase is being replaced by string.ascii_lowercase, so the new error generated are the following:

    ======================================================================
    FAIL: Doctest: modeltests.custom_pk.models.__test__.API_TESTS
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/usr/local/lib/python3.1/dist-packages/django/test/_doctest.py", line 2254, in runTest
        raise self.failureException(self.format_failure(new.getvalue()))
    AssertionError: Failed doctest test for modeltests.custom_pk.models.__test__.API_TESTS
      File "/home/jason/Desktop/workspace/django-3k/build/tests/modeltests/custom_pk/models.py", line unknown line number, in API_TESTS
    
    ----------------------------------------------------------------------
    File "/home/jason/Desktop/workspace/django-3k/build/tests/modeltests/custom_pk/models.py", line ?, in modeltests.custom_pk.models.__test__.API_TESTS
    Failed example:
        try:
           sid = transaction.savepoint()
           Employee.objects.create(employee_code=123, first_name='Fred', last_name='Jones')
           transaction.savepoint_commit(sid)
        except Exception as e:
           if isinstance(e, IntegrityError):
               transaction.savepoint_rollback(sid)
               print("Pass")
           else:
               print("Fail with %s" % type(e))
    Expected:
        Pass
    Got:
        Fail with <class 'TypeError'>
    ----------------------------------------------------------------------
    File "/home/jason/Desktop/workspace/django-3k/build/tests/modeltests/custom_pk/models.py", line ?, in modeltests.custom_pk.models.__test__.API_TESTS
    Failed example:
        f.bar == new_bar
    Exception raised:
        Traceback (most recent call last):
          File "/usr/local/lib/python3.1/dist-packages/django/db/models/fields/related.py", line 257, in __get__
            return getattr(instance, cache_name)
        AttributeError: 'Foo' object has no attribute '_bar_cache'
    
        During handling of the above exception, another exception occurred:
    
        Traceback (most recent call last):
          File "/usr/local/lib/python3.1/dist-packages/django/test/_doctest.py", line 1327, in __run
            compileflags, 1), test.globs)
          File "<doctest modeltests.custom_pk.models.__test__.API_TESTS[40]>", line 1, in <module>
            f.bar == new_bar
          File "/usr/local/lib/python3.1/dist-packages/django/db/models/fields/related.py", line 278, in __get__
            rel_obj = QuerySet(self.field.rel.to).using(db).get(**params)
          File "/usr/local/lib/python3.1/dist-packages/django/db/models/query.py", line 339, in get
            % self.model._meta.object_name)
        modeltests.custom_pk.models.DoesNotExist: Bar matching query does not exist.
    
    
    ----------------------------------------------------------------------
    

    In which the first error belongs to ticket #48

  2. Jason Chen reporter

    Apparently from the code:

    # FIXME: This still doesn't work, but will require some changes in
    # get_db_prep_lookup to fix it.
    # >>> f = Foo.objects.get(bar=new_bar.pk)
    # >>> f == new_foo
    # True
    # >>> f.bar == new_bar
    # True
    

    So the tip from the comment above is to look at the function get_db_prep_lookup in django/contrib/gis/db/models/fields.py for a possible fix.

  3. Log in to comment