Code

Opened 8 years ago

Closed 5 years ago

#2918 closed defect (fixed)

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

Reported by: tklopp@… Owned by: nobody
Component: Database layer (models, ORM) Version:
Severity: blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 (0)

Change History (8)

comment:1 Changed 7 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(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.

comment:2 Changed 7 years ago by russellm

  • Resolution fixed deleted
  • Status changed from closed to reopened

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.

comment:3 Changed 7 years ago by russellm

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

comment:4 Changed 7 years ago by SmileyChris

  • Triage Stage changed from Unreviewed to Accepted

comment:5 Changed 7 years ago by chad@…

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

comment:6 Changed 6 years ago by brosner

  • Component changed from Admin interface to Database wrapper

comment:7 Changed 5 years ago 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?

comment:8 Changed 5 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from reopened to closed

I don't think this is a current bug any longer. Working through the tutorial doesn't raise any such errors.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.