AttributeError'> 'Set' object has no attribute

292 views
Skip to first unread message

Anthony Smith

unread,
Nov 20, 2015, 4:05:06 AM11/20/15
to web2py-users
Hi

This has been driving me crazy, and dont what I am doing wrong


db.define_table('product',
                Field('product_name'),
                Field('batch_no'),
                Field('withholding_period','integer'),
                format='%(product_name)s %(batch_no)s')

db.define_table('stock_task',
Field('completed_date', 'date',default=request.now),
Field('product', db.product),
Field('withhold_until_date', 'date'),
Field('ESI_withhold_until_date', 'date'), #default=withheld), # need to use the completed date and product withhold peroid

def
create_stock_task():
form = SQLFORM (db.stock_task).process()
if form.accepted:
task = db(db.stock_task.id>0).select(limitby=(0,1), orderby=~db.stock_task.id).first()
pdays_row = db(db.stock_task.product==db.product._format)
pdays = pdays_row.withholding_period.select()
wdate_row =db(db.stock_task.completed_date>0).select().first()
fdate = wdate + datetime.timedelta (days + pdays)
ndate_row = db(db.stock_task.withhold_until_date>0).select().first()
ndate = ndate_row.withhold_until_date
db(db.stock_task.id == task).update(ndate=fdate)
session.flash="New Task Added"
redirect(URL('stock_tasks'))
return dict( form=form)

Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
Traceback (most recent call last):
File "/home/tony/web2py/gluon/restricted.py", line 227, in restricted
exec ccode in environment
File "/home/tony/web2py/applications/cps21/controllers/default.py", line 553, in <module>
File "/home/tony/web2py/gluon/globals.py", line 412, in <lambda>
self._caller = lambda f: f()
File "/home/tony/web2py/gluon/tools.py", line 3774, in f
return action(*a, **b)
File "/home/tony/web2py/applications/cps21/controllers/default.py", line 277, in create_stock_task
pdays = pdays_row.withholding_period.select()
AttributeError: 'Set' object has no attribute 'withholding_period'
any help appreciated 

thanks Anthony

Anthony

unread,
Nov 20, 2015, 10:11:52 AM11/20/15
to web2py-users

def create_stock_task():
form = SQLFORM (db.stock_task).process()
if form.accepted:
task = db(db.stock_task.id>0).select(limitby=(0,1), orderby=~db.stock_task.id).first()
pdays_row = db(db.stock_task.product==db.product._format)
pdays = pdays_row.withholding_period.select()

pdays is a DAL Set object, but you are treating it like a Table object (i.e., expecting it to have an attribute called "withholding_period", which is a field in the db.product table). Furthermore, you then apply the .select() method to what appears to be a Field object, which doesn't make sense.

It appears you are expecting pdays to end up being a single integer value, but not clear exactly how that should be calculated. Perhaps you can explain what you are trying to do.

Anthony

Anthony Smith

unread,
Nov 20, 2015, 2:41:59 PM11/20/15
to web2py-users
Hi Anthony,

I am trying to get the product.withholding_period (no of days ,integer) and add to the stock_task.completed _date (date) = stock_task.withhold_until_date (date), where the product is used in each task.

Before I added  format='%(product_name)s %(batch_no)s') to the product table this would work,
"update stock_task, product set withhold_until_date= DATE_ADD(stock_task.completed_date, INTERVAL product.withholding_period DAY)where product.product_name = stock_task.product"

cheers

Anthony

Anthony

unread,
Nov 20, 2015, 3:04:18 PM11/20/15
to web2py-users

Before I added  format='%(product_name)s %(batch_no)s') to the product table this would work,
"update stock_task, product set withhold_until_date= DATE_ADD(stock_task.completed_date, INTERVAL product.withholding_period DAY)where product.product_name = stock_task.product"

Are you saying you were using that raw SQL above for the update previously? If so, it appears in that case, your stock_task.product field was storing the actual value of product.product_name, not the product.id value of the related product record. Adding the "format" argument has nothing to do with this, as it doesn't affect the database model at all. Rather, it appears you instead changed the stock_task.product field to be a reference field, in which case, it is actually storing the product.id value, not the product.product_name value. So, in the above SQL, it would instead be "product.id = stock_task.product".

Anthony

Anthony Smith

unread,
Nov 20, 2015, 3:58:50 PM11/20/15
to web2py-users
Hi Anthony,

Thanks, is ok to use sql or is there a better way of doing this, been new I would rather learn the proper way rather just making it work.


cheers
Anthony 

On Friday, 20 November 2015 20:05:06 UTC+11, Anthony Smith wrote:
Reply all
Reply to author
Forward
0 new messages