Django

Code

Ticket #2918 (reopened)

Opened 2 years ago

Last modified 19 hours ago

"ValueError: too many values to unpack" when doing the tutorial.

Reported by: tklopp@taponet.de Assigned to: nobody
Milestone: Component: Database layer (models, ORM)
Version: Keywords:
Cc: Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

hi, I did my first django installation on a debian/unstable.

I installed sqlite3 and pysqlite2 from debian packages. I installed django-0.95 like shown on http://www.djangoproject.com/documentation/install/.

Here's what I entered and what happened (you can see the error at the bottom):

...
File settings.py saved
tklopp@muschel:~/Projekte/django/mysite$ python manage.py sql polls
BEGIN;
CREATE TABLE "polls_poll" (
    "id" integer NOT NULL PRIMARY KEY,
    "question" varchar(200) NOT NULL,
    "pub_date" datetime NOT NULL
);
CREATE TABLE "polls_choice" (
    "id" integer NOT NULL PRIMARY KEY,
    "poll_id" integer NOT NULL REFERENCES "polls_poll" ("id"),
    "choice" varchar(200) NOT NULL,
    "votes" integer NOT NULL
);
COMMIT;
tklopp@muschel:~/Projekte/django/mysite$ python manage.py validate polls
0 errors found.
tklopp@muschel:~/Projekte/django/mysite$ python manage.py sqlinitialdata
polls
BEGIN;
COMMIT;
tklopp@muschel:~/Projekte/django/mysite$ python manage.py syncdb
Creating table polls_poll
Creating table polls_choice
Adding permission 'poll | Can add poll'
Adding permission 'poll | Can change poll'
Adding permission 'poll | Can delete poll'
Adding permission 'choice | Can add choice'
Adding permission 'choice | Can change choice'
Adding permission 'choice | Can delete choice'
tklopp@muschel:~/Projekte/django/mysite$ python manage.py shell
Python 2.4.4c1 (#2, Oct 12 2006, 21:41:47)
[GCC 4.1.2 20061007 (prerelease) (Debian 4.1.1-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from mysite.polls.models import Poll, Choice
>>> Poll.Objects.all()
Traceback (most recent call last):
  File "<console>", line 1, in ?
AttributeError: type object 'Poll' has no attribute 'Objects'
>>> Poll.objects.all()
[]
>>> from datetime import datetime
>>> p = Poll(question="What's up?", pub_date=datetime.now())
>>> p.save()
>>> p.id()
Traceback (most recent call last):
  File "<console>", line 1, in ?
TypeError: 'int' object is not callable
>>> p.id
1
>>> p.question
"What's up?"
>>> p.pub_date
datetime.datetime(2006, 10, 16, 21, 3, 5, 31007)
>>> p.pub_date = (2006,10,15,21,3,5,31007)
>>> p.save
<bound method Poll.save of <Poll: Poll object>>
>>> p.save)=
  File "<console>", line 1
    p.save)=
          ^
SyntaxError: invalid syntax
>>> p.save()
>>> p.pub_date
(2006, 10, 15, 21, 3, 5, 31007)
>>> Poll.objects.all()
Traceback (most recent call last):
  File "<console>", line 1, in ?
  File
  "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/models/query.py",
  line 97, in __repr__
    return repr(self._get_data())
  File
"/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/models/query.py",
line 430, in _get_data
    self._result_cache = list(self.iterator())
  File
"/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/models/query.py",
line 172, in iterator
    cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "") +
",".join(select) + sql, params)
  File
"/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/backends/util.py",
line 12, in execute
    return self.cursor.execute(sql, params)
  File
"/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/backends/sqlite3/base.py",
line 77, in execute
    return Database.Cursor.execute(self, query, params)
  File
"/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/backends/util.py",
line 62, in typecast_timestamp
    d, t = s.split()
ValueError: too many values to unpack
>>> Poll.objects.all()
Traceback (most recent call last):
  File "<console>", line 1, in ?
  File
  "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/models/query.py",
  line 97, in __repr__
    return repr(self._get_data())
  File
"/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/models/query.py",
line 430, in _get_data
    self._result_cache = list(self.iterator())
  File
"/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/models/query.py",
line 172, in iterator
    cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "") +
",".join(select) + sql, params)
  File
"/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/backends/util.py",
line 12, in execute
    return self.cursor.execute(sql, params)
  File
"/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/backends/sqlite3/base.py",
line 77, in execute
    return Database.Cursor.execute(self, query, params)
  File
"/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/backends/util.py",
line 62, in typecast_timestamp
    d, t = s.split()
ValueError: too many values to unpack
>>>
>>>
>>>
>>>
>>> Poll.objects.all()
Traceback (most recent call last):
  File "<console>", line 1, in ?
  File
  "/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/models/query.py",
  line 97, in __repr__
    return repr(self._get_data())
  File
"/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/models/query.py",
line 430, in _get_data
    self._result_cache = list(self.iterator())
  File
"/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/models/query.py",
line 172, in iterator
    cursor.execute("SELECT " + (self._distinct and "DISTINCT " or "") +
",".join(select) + sql, params)
  File
"/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/backends/util.py",
line 12, in execute
    return self.cursor.execute(sql, params)
  File
"/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/backends/sqlite3/base.py",
line 77, in execute
    return Database.Cursor.execute(self, query, params)
  File
"/usr/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/db/backends/util.py",
line 62, in typecast_timestamp
    d, t = s.split()
ValueError: too many values to unpack
>>> quit
'Use Ctrl-D (i.e. EOF) to exit.'
>>>

tklopp@muschel:~/Projekte/django/mysite$

#######################################################
Next I inserted a line "print s" before line 62.
The output was:

>>> Poll.objects.all()
(2006, 10, 15, 21, 3, 5, 31007)
Traceback (most recent call last):
...

Attachments

Change History

11/02/06 08:24:31 changed by russellm

  • status changed from new to closed.
  • resolution set to fixed.

(In [3960]) Fixes #2918 -- Clarified the db_prep_save logic for DateField? and DateTimeField? to prevent accidental conversion of non-datetime objects into strings, because SQLite doesn't appear to check for valid date format in a string used on an UPDATE of a datetime column.

11/27/06 05:34:30 changed by russellm

  • status changed from closed to reopened.
  • resolution deleted.

Fixes #2993, Refs #2918 -- Reverted [3960]; [3960] fixed a potential data validation problem for SQLite, but broke usage of LazyDate?. The proper fix is to complete the model validators to catch _all_ invalid inputs.

11/27/06 05:36:55 changed by russellm

I forgot to annotate the fact that the last comment refers to changeset [4105]

02/22/07 22:22:01 changed by SmileyChris

  • stage changed from Unreviewed to Accepted.

06/12/07 11:34:51 changed by chad@zetaweb.com

I saw this same error with a time.struct_time as input. That should be automatically converted IMO:

from time import localtime from datetime import datetime x = localtime() datetime(*x[:6])

datetime.datetime(2007, 3, 4, 1, 0, 39)

http://seehuhn.de/pages/pdate

08/01/08 10:34:13 changed by brosner

  • component changed from Admin interface to Database wrapper.

11/30/08 14:29:08 changed by graham_king

I can't replicate this. With Python 2.5.2 and latest Django from SVN doing:

p.pub_date = (2006,10,15,21,3,5,31007) p.save()

correctly throws a ValidationError?.

Can this be closed?


Add/Change #2918 ("ValueError: too many values to unpack" when doing the tutorial.)




Change Properties
Action