Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should RemoteForeignKey support NULL or empty value? #9

Open
jsaytoe opened this issue Jun 4, 2013 · 2 comments
Open

Should RemoteForeignKey support NULL or empty value? #9

jsaytoe opened this issue Jun 4, 2013 · 2 comments

Comments

@jsaytoe
Copy link
Contributor

jsaytoe commented Jun 4, 2013

I want to have a model that contain RemoteForeignKey field and i want this field to be nullable. I got database initialize successfully but i also got error when i created an model instance via Django python shell.

@KayEss
Copy link
Member

KayEss commented Jun 4, 2013

Can you show me what the field in the model looks like and what error you're getting? The code that produces the error would also help.

It should work the way that Django normally does it, using blank=True etc.

@jsaytoe
Copy link
Contributor Author

jsaytoe commented Jun 4, 2013

My Model example is below:
class Test(Model):
customer = RemoteForeignKey(model_url='slumber://c_service/Customer/')
payment = RemoteForeignKey(model_url='slumber://l_service/Payment/', null=True,blank=True)

when i created the Test model instance with only customer detail, i got the error as below:

import Test
t_object = Test.objects.create(customer = "slumber://c_service/Customer/data/1/")
Traceback (most recent call last):
File "", line 1, in
File "/home/jsaytoe/workspace/virtual_env/shop/local/lib/python2.7/site-packages/django/db/models/manager.py", line 137, in create
return self.get_query_set().create(*_kwargs)
File "/home/jsaytoe/workspace/virtual_env/shop/local/lib/python2.7/site-packages/django/db/models/query.py", line 377, in create
obj.save(force_insert=True, using=self.db)
File "/home/jsaytoe/workspace/virtual_env/shop/local/lib/python2.7/site-packages/django/db/models/base.py", line 463, in save
self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/home/jsaytoe/workspace/virtual_env/shop/local/lib/python2.7/site-packages/django/db/models/base.py", line 551, in save_base
result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "/home/jsaytoe/workspace/virtual_env/shop/local/lib/python2.7/site-packages/django/db/models/manager.py", line 203, in _insert
return insert_query(self.model, objs, fields, *_kwargs)
File "/home/jsaytoe/workspace/virtual_env/shop/local/lib/python2.7/site-packages/django/db/models/query.py", line 1593, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/jsaytoe/workspace/virtual_env/shop/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 911, in execute_sql
for sql, params in self.as_sql():
File "/home/jsaytoe/workspace/virtual_env/shop/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 872, in as_sql
for obj in self.query.objs
File "/home/jsaytoe/workspace/virtual_env/shop/local/lib/python2.7/site-packages/django/db/models/fields/init.py", line 292, in get_db_prep_save
prepared=False)
File "/home/jsaytoe/workspace/virtual_env/shop/local/lib/python2.7/site-packages/slumber/fields.py", line 37, in get_db_prep_value
url = to_slumber_scheme(value._url, get_slumber_services())
AttributeError: 'NoneType' object has no attribute '_url'

I think we should take care on both get_prep_value and get_db_prep_value method in fields.py file for support null value

Hope this information help us to fix the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants