Hello,

I have a simple script (attached to this email )- and evrytime I run, i got


ste...@lenovo:~/hang-hieu-uc/python$ python bulk_price_update.py
Number of record: 202
/usr/lib/python2.6/dist-packages/storm/database.py:342: Warning: Data
truncated for column 'amount' at row 1
  return function(*args, **kwargs)
Traceback (most recent call last):
  File "bulk_price_update.py", line 137, in <module>
    process()
  File "bulk_price_update.py", line 129, in process
    new_pt.product_discount_id = new_pd.id; store.flush()
  File "/usr/lib/python2.6/dist-packages/storm/properties.py", line 60, in
__get__
    return obj_info.variables[column].get()
  File "/usr/lib/python2.6/dist-packages/storm/variables.py", line 178, in
get
    self.event.emit("resolve-lazy-value", self, self._lazy_value)
  File "/usr/lib/python2.6/dist-packages/storm/event.py", line 53, in emit
    if callback(owner, *(args+data)) is False:
  File "/usr/lib/python2.6/dist-packages/storm/store.py", line 891, in
_resolve_lazy_value
    result, result.get_one())
  File "/usr/lib/python2.6/dist-packages/storm/store.py", line 746, in
_set_values
    raise LostObjectError("Can't obtain values from the database "
storm.exceptions.LostObjectError: Can't obtain values from the database
(object got removed?)

I am stuck at new idea to fix it, please help

If I do not modify the product_discount_id of a product then it printed
values fine and create in the history table fine. First I directly modify
the  pt object, but then try to get a product again using pt.id, however it
does not help in both cases.

The DB is VirutalMart DB if it helps

Many thanks in advance



-- 
Steve Kieu
#!/usr/bin/env python

from storm.locals import *
# storm Decimal conflict with that, if we import it, all value will be 0
#from decimal import * 
#getcontext().prec = 5
from storm.expr import Count, Alias, Asc, Desc
import time

class Product(Storm):
	__storm_table__ = 'jos_vm_product'
	id = Int(name='product_id', primary=True)
 	vendor_id = Int()
 	product_parent_id = Int()
 	product_sku = Unicode()
 	product_s_desc = Unicode()
 	product_desc = Unicode()
 	product_thumb_image = Unicode()
 	product_full_image = Unicode()
 	product_publish = Unicode()
 	product_weight = Decimal()
 	product_weight_uom = Unicode()
 	product_length = Decimal()
 	product_width = Decimal()
 	product_height = Decimal()
 	product_lwh_uom = Unicode()
 	product_url = Unicode()
 	product_in_stock = Int()
 	product_available_date = Int()
 	product_availability = Unicode()
 	product_special = Unicode()
 	product_discount_id = Int()
	product_discount = Reference(product_discount_id, 'ProductDiscount.id')
 	ship_code_id = Int()
 	cdate = Int()
 	mdate = Int()
 	product_name = Unicode()
 	product_sales = Int()
 	attribute = Unicode()
 	custom_attribute = Unicode()
 	product_tax_id = Int()
 	product_unit = Unicode()
 	product_packaging = Int()
 	child_options = Unicode()
 	quantity_options = Unicode()
 	child_option_ids = Unicode()
 	product_order_levels = Unicode()
	def __init__(self, id):
		self.id = id; store.add(self); store.flush()
	@classmethod
	def getone(cls, **a):
		if a.has_key('id'):
			one = store.get(Product, a['id'])
			if not one: one = Product(a['id'])
			return one

class ProductPrice(Storm):
	__storm_table__ = 'jos_vm_product_price'
	id = Int(name='product_price_id', primary=True)
	product_id = Int()
	product = Reference(product_id, Product.id)
	product_price = Decimal()
	product_currency = Unicode()
	product_price_vdate = Int()
	product_price_edate = Int()
	cdate = Int()
	mdate = Int()
	shopper_group_id = Int()
	price_quantity_start = Int()
	price_quantity_end = Int()
	def __init__(self, id):
		self.id = id; store.add(self); store.flush()
	@classmethod
	def getone(cls, **a):
		if a.has_key('id'):
			one = store.get(ProductPrice, a['id'])
			if not one: one = ProductPrice(a['id'])
			return one

	
class ProductDiscount(Storm):
	__storm_table__ = 'jos_vm_product_discount'
	__storm_primary__ = 'amount', 'is_percent', 'start_date'
	id = Int(name='discount_id', primary=True)
	amount = Decimal()
	is_percent = Int()
	start_date = Int()
	end_date = Int()
	def __init__(self, amount, is_percent, start_date):
		self.amount, self.is_percent, self.start_date = amount, is_percent, start_date
		store.add(self); store.flush()
	@classmethod
	def getone(cls, amount, is_percent, start_date):
		one = store.get(ProductDiscount, (amount, is_percent, start_date) ) 
		if not one: one = ProductDiscount(amount, is_percent, start_date)
		return one

class ProductDiscountHistory(Storm):
	__storm_table__ = 'skieu_product_discount_history'
	__storm_primary__ = 'product_discount_id', 'product_id', 'end_date'
	id = Int()
	product_discount_id = Int()
	product_id = Int()
	start_date = Int()
	end_date = Int()
	def __init__(self,pdid,pid,endate):
		self.product_discount_id, self.product_id, self.end_date = pdid, pid, endate
		store.add(self); store.flush()
	@classmethod
	def getone(cls,pdid,pid,endate):
		one = store.get(ProductDiscountHistory, (pdid,pid,endate)  )
		if not one: one = ProductDiscountHistory(pdid,pid,endate)
		return one

def process():
	resultset = store.find((Product, ProductPrice, ProductDiscount ), ProductPrice.product_id == Product.id, Product.product_discount_id == ProductDiscount.id )
    	print "Number of record: %s" % resultset.count()
	count = 0
	for (pt, pr, pd) in resultset:
		count += 1
		pd_history = ProductDiscountHistory.getone(pd.id, pt.id, int(time.time()) )
		if (pd.is_percent == 0): current_sale_price = pr.product_price - pd.amount
		else: current_sale_price = pr.product_price * pd.amount
		new_percentage = current_sale_price / (2 * pr.product_price)
		new_pd = ProductDiscount.getone(new_percentage, 1, int(time.time())  )
		new_pd.end_date = time.mktime(time.strptime("19/01/2011", "%d/%m/%Y") )
		old = pt.product_discount_id
		new_pt = store.get(Product, pt.id)
		new_pt.product_discount_id = new_pd.id; store.flush()
	        print "Old: %s, New: %s" % ( old,  new_pt.product_discount_id)

	print count

if (__name__ == '__main__'):
	dsn = "mysql://username:pas...@host/dbname"
	store = Store(create_database(dsn))
	process()

-- 
storm mailing list
[email protected]
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/storm

Reply via email to