Hi,
I am facing a strange error where in when I am trying to save a file with save_file
function in frappe I am getting the out of range value for column file_size now I have the following details as below:
Error Code:
Traceback (most recent call last):
File "/home/aditya/frappe-bench/apps/frappe/frappe/app.py", line 62, in application
response = frappe.handler.handle()
File "/home/aditya/frappe-bench/apps/frappe/frappe/handler.py", line 22, in handle
data = execute_cmd(cmd)
File "/home/aditya/frappe-bench/apps/frappe/frappe/handler.py", line 53, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File "/home/aditya/frappe-bench/apps/frappe/frappe/__init__.py", line 940, in call
return fn(*args, **newargs)
File "/home/aditya/frappe-bench/apps/frappe/frappe/handler.py", line 81, in runserverobj
frappe.desk.form.run_method.runserverobj(method, docs=docs, dt=dt, dn=dn, arg=arg, args=args)
File "/home/aditya/frappe-bench/apps/frappe/frappe/desk/form/run_method.py", line 36, in runserverobj
r = doc.run_method(method)
File "/home/aditya/frappe-bench/apps/frappe/frappe/model/document.py", line 755, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File "/home/aditya/frappe-bench/apps/frappe/frappe/model/document.py", line 1029, in composer
return composed(self, method, *args, **kwargs)
File "/home/aditya/frappe-bench/apps/frappe/frappe/model/document.py", line 1012, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File "/home/aditya/frappe-bench/apps/frappe/frappe/model/document.py", line 749, in <lambda>
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File "/home/aditya/frappe-bench/apps/rigpl_erpnext/rigpl_erpnext/rigpl_erpnext/doctype/carrier_tracking/carrier_tracking.py", line 118, in book_shipment
from_country_doc, to_country_doc, transporter_doc, contact_doc)
File "/home/aditya/frappe-bench/apps/rigpl_erpnext/rigpl_erpnext/rigpl_erpnext/doctype/carrier_tracking/carrier_tracking.py", line 165, in create_shipment_service
self.store_label(self, shipment, tracking_id, self.doctype, self.name)
File "/home/aditya/frappe-bench/apps/rigpl_erpnext/rigpl_erpnext/rigpl_erpnext/doctype/carrier_tracking/carrier_tracking.py", line 435, in store_label
self.store_file('FEDEX-ID-{0}.pdf'.format(tracking_id), label_data, ps_doctype, ps_name)
File "/home/aditya/frappe-bench/apps/rigpl_erpnext/rigpl_erpnext/rigpl_erpnext/doctype/carrier_tracking/carrier_tracking.py", line 443, in store_file
save_file(file_name, image_data, ps_doctype, ps_name, is_private=1)
File "/home/aditya/frappe-bench/apps/frappe/frappe/utils/file_manager.py", line 157, in save_file
f.insert()
File "/home/aditya/frappe-bench/apps/frappe/frappe/model/document.py", line 239, in insert
self.run_method("after_insert")
File "/home/aditya/frappe-bench/apps/frappe/frappe/model/document.py", line 755, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File "/home/aditya/frappe-bench/apps/frappe/frappe/model/document.py", line 1029, in composer
return composed(self, method, *args, **kwargs)
File "/home/aditya/frappe-bench/apps/frappe/frappe/model/document.py", line 1012, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File "/home/aditya/frappe-bench/apps/frappe/frappe/model/document.py", line 749, in <lambda>
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File "/home/aditya/frappe-bench/apps/frappe/frappe/core/doctype/file/file.py", line 57, in after_insert
self.update_parent_folder_size()
File "/home/aditya/frappe-bench/apps/frappe/frappe/core/doctype/file/file.py", line 132, in update_parent_folder_size
frappe.get_doc("File", self.folder).set_folder_size()
File "/home/aditya/frappe-bench/apps/frappe/frappe/core/doctype/file/file.py", line 114, in set_folder_size
self.db_set('file_size', self.file_size)
File "/home/aditya/frappe-bench/apps/frappe/frappe/model/document.py", line 962, in db_set
self.modified, self.modified_by, update_modified=update_modified)
File "/home/aditya/frappe-bench/apps/frappe/frappe/database.py", line 685, in set_value
values, debug=debug)
File "/home/aditya/frappe-bench/apps/frappe/frappe/database.py", line 173, in sql
self._cursor.execute(query, values)
File "/home/aditya/frappe-bench/env/lib/python3.5/site-packages/pymysql/cursors.py", line 165, in execute
result = self._query(query)
File "/home/aditya/frappe-bench/env/lib/python3.5/site-packages/pymysql/cursors.py", line 321, in _query
conn.query(q)
File "/home/aditya/frappe-bench/env/lib/python3.5/site-packages/pymysql/connections.py", line 860, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/home/aditya/frappe-bench/env/lib/python3.5/site-packages/pymysql/connections.py", line 1061, in _read_query_result
result.read()
File "/home/aditya/frappe-bench/env/lib/python3.5/site-packages/pymysql/connections.py", line 1349, in read
first_packet = self.connection._read_packet()
File "/home/aditya/frappe-bench/env/lib/python3.5/site-packages/pymysql/connections.py", line 1018, in _read_packet
packet.check_error()
File "/home/aditya/frappe-bench/env/lib/python3.5/site-packages/pymysql/connections.py", line 384, in check_error
err.raise_mysql_exception(self._data)
File "/home/aditya/frappe-bench/env/lib/python3.5/site-packages/pymysql/err.py", line 107, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.DataError: (1264, "Out of range value for column 'file_size' at row 1")
Now my file_size value which I got from debug was 146553 and also when I checked my backend mysql database I got this as below:
rigpl.local> DESCRIBE `tabFile`;
+-----------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------+--------------+------+-----+---------+-------+
| name | varchar(255) | NO | PRI | <null> | |
| creation | datetime(6) | YES | | <null> | |
| modified | datetime(6) | YES | | <null> | |
| modified_by | varchar(255) | YES | | <null> | |
| owner | varchar(255) | YES | | <null> | |
| docstatus | int(1) | NO | | 0 | |
| parent | varchar(255) | YES | MUL | <null> | |
| parentfield | varchar(255) | YES | | <null> | |
| parenttype | varchar(255) | YES | | <null> | |
| idx | int(8) | YES | | <null> | |
| file_name | varchar(140) | YES | | <null> | |
| _user_tags | text | YES | | <null> | |
| file_url | longtext | YES | | <null> | |
| attached_to_name | varchar(140) | YES | MUL | <null> | |
| file_size | int(11) | NO | | 0 | |
| attached_to_doctype | varchar(140) | YES | MUL | <null> | |
| content_hash | varchar(140) | YES | MUL | <null> | |
| rgt | int(11) | NO | | 0 | |
| old_parent | varchar(140) | YES | | <null> | |
| lft | int(11) | NO | | 0 | |
| is_home_folder | int(1) | NO | | 0 | |
| is_attachments_folder | int(1) | NO | | 0 | |
| is_folder | int(1) | NO | | 0 | |
| folder | varchar(140) | YES | | <null> | |
| thumbnail_url | text | YES | | <null> | |
| is_private | int(1) | NO | | 0 | |
| _comments | text | YES | | <null> | |
| _liked_by | text | YES | | <null> | |
| _assign | text | YES | | <null> | |
| attached_to_field | varchar(140) | YES | | <null> | |
+-----------------------+--------------+------+-----+---------+-------+
30 rows in set
Time: 0.097s
rigpl.local>
The error is gone if I change the file_size to varchar(11) which I think is wrong but just did not want to get stuck on this issue for long.
What could be issue since its quite perplexing to get this error out of nowhere?