Re: meta.OneToOneField() problemo
Adrian, http://code.djangoproject.com/ticket/527 Any progress with this issue? I am going to try and dig through the code myself this weekend but I wanted to make sure I wasn't repeating any effort. Also, let me know if there are any tips or ideas on where to start obviously meta/__init__.py is probably a good place ;). thanks- Ian On 9/19/05, Adrian Holovaty <[EMAIL PROTECTED]> wrote: > > On 9/19/05, Ian Maurer <[EMAIL PROTECTED]> wrote: > > But, I have a multitude of problems that I don't believe I had before > > the recent model overhaul. Here are some example things I tried doing > > with my Waiter class that I believe should work: > > Hey Ian, > > It'd be a huge help if you could add some unit tests to > tests/testapp/models/one_to_one.py and post them back to the list. > > Adrian > > -- > Adrian Holovaty > holovaty.com | djangoproject.com | chicagocrime.org >
Re: meta.OneToOneField() problemo
On 9/19/05, Ian Maurer <[EMAIL PROTECTED]> wrote: > First, I ran into an issue with runtests.py since I use MySQL. The DB > connection autocommit requires an integer value and the current code > throws a TypeError for me. So the real brain-dead way around this was: Hey Ian, Turns out the other database wrappers (Postgres and SQLite) don't mind if you pass an integer value to autocommit(), so I've added that to the code in revision 805. Thanks again for the heads-up on this! Adrian -- Adrian Holovaty holovaty.com | djangoproject.com | chicagocrime.org
Re: meta.OneToOneField() problemo
> "svn diff" is great, in most cases. I just created this page, which > gives more details: > > http://code.djangoproject.com/wiki/PatchGuidelines Great, thanks... I felt dumb not knowing. Glad I asked. > > First, I ran into an issue with runtests.py since I use MySQL. The DB > > connection autocommit requires an integer value and the current code > > throws a TypeError for me. > > Hmmm, that shouldn't be happening. Which versions of MySQL and MySQLdb > (the Python bindings) are you using? The unit tests work here, with > MySQL 3.23.58 and MySQLdb 0.9.2. I guess that's our issue... not sure what has changed or why. I haven't had a chance to investigate it. MySQL 4.0.24 MySQLdb 1.2 Python 2.4 > > Here are my modifications to one-to-one.py: > > Thanks for those unit tests! I'm rolling them in now... And I watching this ticket... http://code.djangoproject.com/ticket/527 thanks! Ian
Re: meta.OneToOneField() problemo
On 9/19/05, Ian Maurer <[EMAIL PROTECTED]> wrote: > First, I am using 'svn diff' for submitting my patches, let me know if > there is a preferred way... especially when posting to Trac. "svn diff" is great, in most cases. I just created this page, which gives more details: http://code.djangoproject.com/wiki/PatchGuidelines > First, I ran into an issue with runtests.py since I use MySQL. The DB > connection autocommit requires an integer value and the current code > throws a TypeError for me. Hmmm, that shouldn't be happening. Which versions of MySQL and MySQLdb (the Python bindings) are you using? The unit tests work here, with MySQL 3.23.58 and MySQLdb 0.9.2. > Here are my modifications to one-to-one.py: Thanks for those unit tests! I'm rolling them in now... Adrian -- Adrian Holovaty holovaty.com | djangoproject.com | chicagocrime.org
Re: meta.OneToOneField() problemo
First, I am using 'svn diff' for submitting my patches, let me know if there is a preferred way... especially when posting to Trac. First, I ran into an issue with runtests.py since I use MySQL. The DB connection autocommit requires an integer value and the current code throws a TypeError for me. So the real brain-dead way around this was: Index: runtests.py === --- runtests.py (revision 647) +++ runtests.py (working copy) @@ -97,6 +97,8 @@ db.connection.autocommit() except AttributeError: pass +except TypeError: # For MySQL Users +db.connection.autocommit(1) self.output(1, "Creating test database") try: cursor.execute("CREATE DATABASE %s" % TEST_DATABASE_NAME) @@ -183,6 +185,8 @@ db.connection.autocommit() except AttributeError: pass +except TypeError: # For MySQL Users +db.connection.autocommit(1) else: time.sleep(1) # To avoid "database is being accessed by other users" errors. cursor.execute("DROP DATABASE %s" % TEST_DATABASE_NAME) Here are my modifications to one-to-one.py: Index: one_to_one.py === --- one_to_one.py (revision 647) +++ one_to_one.py (working copy) @@ -23,6 +23,13 @@ def __repr__(self): return "%s the restaurant" % self.get_place().name +class Waiter(meta.Model): +restaurant = meta.ForeignKey(Restaurant) +name = meta.CharField(maxlength=50) + +def __repr__(self): +return "%s the waiter at %s" % (self.name, self.get_restaurant()) + API_TESTS = """ # Create a couple of Places. >>> p1 = places.Place(name='Demon Dogs', address='944 W. Fullerton') @@ -61,4 +68,10 @@ Demon Dogs the restaurant >>> restaurants.get_object(pk=1) Demon Dogs the restaurant + +# Add Waiter to Restaurant. +>>> w = r.add_waiter(name="Joe") +>>> w.save() +>>> w +Joe the waiter at Demon Dogs the restaurant """ My tests failed spectacularly... Running tests with database 'mysql' 'one_to_one' module: API test raised an exception = Code: 'w = r.add_waiter(name="Joe")' Line: 40 Exception: File "C:\www\downloads\trunk\tests\doctest.py", line 1243, in __run compileflags, 1) in test.globs File "", line 1, in ? w = r.add_waiter(name="Joe") File "C:\www\django\utils\functional.py", line 3, in _curried return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items())) File "C:\www\django\core\meta\__init__.py", line 944, in method_add_related obj = rel_mod.Klass(**init_kwargs) File "C:\www\django\utils\functional.py", line 3, in _curried return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items())) File "C:\www\django\core\meta\__init__.py", line 755, in method_init raise TypeError, "Invalid value: %r should be a %s instance, not a %s" % (f.name, f.rel.to, type(rel_obj)) TypeError: Invalid value: 'restaurant' should be a instance, not a 'one_to_one' module: API test raised an exception = Code: 'w.save()' Line: 41 Exception: File "C:\www\downloads\trunk\tests\doctest.py", line 1243, in __run compileflags, 1) in test.globs File "", line 1, in ? w.save() NameError: name 'w' is not defined 'one_to_one' module: API test raised an exception = Code: 'w' Line: 42 Exception: File "C:\www\downloads\trunk\tests\doctest.py", line 1243, in __run compileflags, 1) in test.globs File "", line 1, in ? w NameError: name 'w' is not defined Let me know if I can improve on how I submit my future contributions... regards, Ian Adrian Holovaty wrote: > On 9/19/05, Ian Maurer <[EMAIL PROTECTED]> wrote: > > But, I have a multitude of problems that I don't believe I had before > > the recent model overhaul. Here are some example things I tried doing > > with my Waiter class that I believe should work: > > Hey Ian, > > It'd be a huge help if you could add some unit tests to > tests/testapp/models/one_to_one.py and post them back to the list. > > Adrian > > -- > Adrian Holovaty > holovaty.com | djangoproject.com | chicagocrime.org
Re: meta.OneToOneField() problemo
On 9/19/05, Ian Maurer <[EMAIL PROTECTED]> wrote: > But, I have a multitude of problems that I don't believe I had before > the recent model overhaul. Here are some example things I tried doing > with my Waiter class that I believe should work: Hey Ian, It'd be a huge help if you could add some unit tests to tests/testapp/models/one_to_one.py and post them back to the list. Adrian -- Adrian Holovaty holovaty.com | djangoproject.com | chicagocrime.org
Re: meta.OneToOneField() problemo
Sorry Mark, But I am going to add to your problem since I encountered something this weekend that was similar. If I add a Waiter class to this example: class Waiter(meta.Model): name = meta.CharField(maxlength=50) restaurant = meta.ForeignKey(Restaurant) def __repr__(self): return "%s waits at %s" % (self.name, self.get_restaurant()) But, I have a multitude of problems that I don't believe I had before the recent model overhaul. Here are some example things I tried doing with my Waiter class that I believe should work: from django.models.places import places, restaurants, waiters # Works Fine p = places.Place(name='Demon Dogs', address='944 W. Fullerton') p.save() # Works Fine r = restaurants.Restaurant(place=p, serves_hot_dogs=True, serves_pizza=False) r.save() # This Fails: w = r.add_waiter(name="John Doe") #Traceback (most recent call last): # File "test_places.py", line 13, in ? #w = r.add_waiter(name="John Doe") # File "C:\www\django\utils\functional.py", line 3, in _curried #return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items())) # File "C:\www\django\core\meta\__init__.py", line 944, in method_add_related #obj = rel_mod.Klass(**init_kwargs) # File "C:\www\django\utils\functional.py", line 3, in _curried #return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items())) # File "C:\www\django\core\meta\__init__.py", line 755, in method_init #raise TypeError, "Invalid value: %r should be a %s instance, not a %s" % (f.name, f.rel.to, type(rel_obj)) #TypeError: Invalid value: 'restaurant' should be a instance, not a # So Does This: w = waiters.Waiter(restaurant=r, name="John Doe") #Traceback (most recent call last): # File "test_places.py", line 27, in ? #w = waiters.Waiter(restaurant=r, name="John Doe") # File "C:\www\django\utils\functional.py", line 3, in _curried #return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items())) # File "C:\www\django\core\meta\__init__.py", line 755, in method_init #raise TypeError, "Invalid value: %r should be a %s instance, not a %s" % (f.name, f.rel.to, type(rel_obj)) #TypeError: Invalid value: 'restaurant' should be a instance, not a # This Hack Works w = waiters.Waiter(restaurant_id=r.place_id, name="John Doe") w.save() # But Even with a Correct Data Structure this Fails print w.get_restaurant() #Traceback (most recent call last): # File "test_places.py", line 43, in ? #print w.get_restaurant() # File "C:\www\django\utils\functional.py", line 3, in _curried #return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items())) # File "C:\www\django\core\meta\__init__.py", line 873, in method_get_many_to_one #retrieved_obj = mod.get_object(**{'%s__exact' % field_with_rel.rel.field_name: val}) # File "C:\www\django\utils\functional.py", line 3, in _curried #return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items())) # File "C:\www\django\core\meta\__init__.py", line 1083, in function_get_object #obj_list = function_get_list(opts, klass, **kwargs) # File "C:\www\django\core\meta\__init__.py", line 1123, in function_get_list #return list(function_get_iterator(opts, klass, **kwargs)) # File "C:\www\django\core\meta\__init__.py", line 1105, in function_get_iterator #select, sql, params = function_get_sql_clause(opts, **kwargs) # File "C:\www\django\core\meta\__init__.py", line 1302, in function_get_sql_clause #tables2, join_where2, where2, params2, _ = _parse_lookup(kwargs.items(), opts) # File "C:\www\django\core\meta\__init__.py", line 1231, in _parse_lookup #_throw_bad_kwarg_error(kwarg) # File "C:\www\django\core\meta\__init__.py", line 1181, in _throw_bad_kwarg_error #raise TypeError, "got unexpected keyword argument '%s'" % kwarg #TypeError: got unexpected keyword argument 'place__exact' Originally, I was going to ditch the use of OneToOne because I thought I was simply using it incorrectly in my design... but after seeing Mark's post and whipping up this example, I believe there is a bug. I also hope my post clarifies not confuses Mark's post... because I believe they are related issues. regards, -ian