Related
I've only been learning odoo-14 for 2 weeks.
There are three compute functions in my code. But I got the error:
Odoo Server Error
Traceback (most recent call last):
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/addons/base/models/ir_http.py", line 237, in _dispatch
result = request.dispatch()
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/http.py", line 685, in dispatch
result = self._call_function(**self.params)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/http.py", line 361, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/service/model.py", line 94, in wrapper
return f(dbname, *args, **kwargs)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/http.py", line 349, in checked_call
result = self.endpoint(*a, **kw)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/http.py", line 914, in __call__
return self.method(*args, **kw)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/http.py", line 533, in response_wrap
response = f(*args, **kw)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/addons/web/controllers/main.py", line 1394, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/addons/web/controllers/main.py", line 1386, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/api.py", line 399, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/api.py", line 386, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/models.py", line 3022, in read
return self._read_format(fnames=fields, load=load)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/models.py", line 3042, in _read_format
vals[name] = convert(record[name], record, use_name_get)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/models.py", line 5686, in __getitem__
return self._fields[key].__get__(self, type(self))
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/fields.py", line 3149, in __get__
return super().__get__(records, owner)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/fields.py", line 2485, in __get__
return super().__get__(records, owner)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/fields.py", line 1028, in __get__
raise ValueError("Compute method failed to assign %s.%s" % (record, self.name))
Exception
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/http.py", line 641, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/http.py", line 317, in _handle_exception
raise exception.with_traceback(None) from new_cause
ValueError: Compute method failed to assign custom.module.solicitud(11,).historial_ids
#################################My model#########################################
class CustomModuleSolicitud(models.Model):
_name = 'custom.module.solicitud'
_description = "Solicitud"
_order = "create_date desc, id desc"
....
state = fields.Selection([('pendiente', 'Pendiente'), ('actualizado', 'Actualizado')],
string='Estado', default='pendiente', readonly=True, required=True)
agrupacion = fields.Char(string="AgrupaciĆ³n", readonly=True)
historial_ids = fields.One2many(comodel_name='custom.module.solicitud', string="Solicitudes", compute='_compute_historial')
....
#api.depends('agrupacion')
def _compute_historial(self):
for r in self:
if not r.agrupacion:
r.historial_ids = []
else:
r.historial_ids = self.env['custom.module.solicitud'].search([('agrupacion', '=', r.agrupacion),
('id', '!=', r.id),
('state', '=', 'actualizado')])
I think the error is related to the field type one2many. Please help to find why i got this error.
Set the default value of historial_ids to False.
To avoid the following error:
psycopg2.errors.InvalidTextRepresentation: invalid input syntax for type integer: "NewId_0x7f7bb5dfceb0"
Use set operations to filter out the current record from the search result
Example:
#api.depends('agrupacion')
def _compute_historial(self):
for r in self:
if not r.agrupacion:
r.historial_ids = False
else:
r.historial_ids = self.env['custom.module.solicitud'].search(
[('agrupacion', '=', r.agrupacion),('state', '=', 'actualizado')]) - r
Finally I solved the problem in the following way:
#api.depends('agrupacion')
def _compute_historial(self):
for r in self:
hids = r.historial_ids
if not r.agrupacion:
hids = []
else:
hids = self.env['etecsa.solicitud'].search([('agrupacion', '=', r.agrupacion),
('id', '!=', hids.id),
('state', '=', 'actualizado')])
This question already has answers here:
Why do I get AttributeError: 'NoneType' object has no attribute 'something'?
(11 answers)
Closed 1 year ago.
I'm getting the error when trying to get all the Urls for which the limited field is True. I've tried deleting the migrations and creating new migrations, but still getting the same error.
these are the installed dependencies:
asgiref==3.4.1
backports.zoneinfo==0.2.1
Django==4.0
django-cors-headers==3.10.1
django-shell-plus==1.1.7
djangorestframework==3.13.1
djongo==1.3.6
dnspython==2.1.0
gunicorn==20.1.0
pymongo==3.12.1
python-dotenv==0.19.2
pytz==2021.3
sqlparse==0.2.4
tzdata==2021.5
models.py:
class Urls(models.Model):
_id = models.ObjectIdField()
record_id = models.IntegerField(unique=True)
hash = models.CharField(unique=True, max_length=1000)
long_url = models.URLField()
created_at = models.DateField(auto_now_add=True)
expires_in = models.DurationField(default=timedelta(days=365*3))
expires_on = models.DateField(null=True, blank=True)
limited = models.BooleanField()
exhausted = models.BooleanField()
query:
Urls.objects.filter(limited=False)
error:
Traceback (most recent call last):
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 857, in parse
return handler(self, statement)
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 933, in _select
return SelectQuery(self.db, self.connection_properties, sm, self._params)
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 116, in __init__
super().__init__(*args)
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 62, in __init__
self.parse()
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 152, in parse
self.where = WhereConverter(self, statement)
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/djongo/sql2mongo/converters.py", line 27, in __init__
self.parse()
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/djongo/sql2mongo/converters.py", line 119, in parse
self.op = WhereOp(
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/djongo/sql2mongo/operators.py", line 476, in __init__
self.evaluate()
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/djongo/sql2mongo/operators.py", line 465, in evaluate
op.evaluate()
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/djongo/sql2mongo/operators.py", line 258, in evaluate
self.rhs.negate()
AttributeError: 'NoneType' object has no attribute 'negate'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/djongo/cursor.py", line 51, in execute
self.result = Query(
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 784, in __init__
self._query = self.parse()
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/djongo/sql2mongo/query.py", line 885, in parse
raise exe from e
djongo.exceptions.SQLDecodeError:
Keyword: None
Sub SQL: None
FAILED SQL: SELECT "short_urls"."_id", "short_urls"."record_id", "short_urls"."hash", "short_urls"."long_url", "short_urls"."created_at", "short_urls"."expires_in", "short_urls"."expires_on", "short_urls"."limited", "short_urls"."exhausted" FROM "short_urls" WHERE NOT "short_urls"."limited" LIMIT 21
Params: ()
Version: 1.3.6
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/djongo/cursor.py", line 59, in execute
raise db_exe from e
djongo.database.DatabaseError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/django/db/models/query.py", line 256, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/django/db/models/query.py", line 262, in __len__
self._fetch_all()
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/django/db/models/query.py", line 1354, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/django/db/models/query.py", line 51, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1202, in execute_sql
cursor.execute(sql, params)
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/django/db/backends/utils.py", line 99, in execute
return super().execute(sql, params)
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/mnt/c/Users/pranjal/Desktop/urlhash/env/lib/python3.8/site-packages/djongo/cursor.py", line 59, in execute
raise db_exe from e
django.db.utils.DatabaseError
I would need to see your views.py where you do that query, Urls.objects.filter(limited=False) but first, perhaps the query is not finding any Urls objects that match the criteria, limited=False, thus the query returns None, which has no attributes. Second, I'm not familiar with negate. I don't see it in your model. Perhaps if I see the views.py where you make that query I will understand better.
MRE:
Created a dataset from Fusion
Created a transformation in Code Workbook
def unnamed(src):
src.createOrReplaceTempView('view_src')
df = spark.sql(f"""SELECT * FROM view_src""")
return df
Traceback (most recent call last):
File "unnamed", line 1, in <module>
File "unnamed", line 3, in unnamed
File "/opt/conda/lib/python3.7/site-packages/pyspark/sql/session.py", line 649, in sql
return DataFrame(self._jsparkSession.sql(sqlQuery), self._wrapped)
File "/opt/conda/lib/python3.7/site-packages/py4j/java_gateway.py", line 1305, in __call__
answer, self.gateway_client, self.target_id, self.name)
File "/opt/conda/lib/python3.7/site-packages/pyspark/sql/utils.py", line 128, in deco
return f(*a, **kw)
File "/opt/conda/lib/python3.7/site-packages/py4j/protocol.py", line 328, in get_return_value
format(target_id, ".", name), value)
py4j.protocol.Py4JJavaError: An error occurred while calling o651.sql.
: com.palantir.foundry.spark.api.errors.DatasetPathNotFoundException: view_src
...
How to get back this table as a dataframe from the temp view?
I have also tried createOrReplaceGlobalTempView.
In Code Repositories the given code snippet works fine.
I want to write a Pandas UDF function with GroupMAP like this:
schema_str = "ID string, EVENTS array<string>"
#pandas_udf(schema_str, PandasUDFType.GROUPED_MAP)
def my_udf(key, data):
# Creates DataFrame.
zero_row = np.zeros(shape=(1,2))
column_names = ["ID", "EVENTS"]
seq_df = pd.DataFrame(zero_row, columns=column_names)
seq_df['ID'] = "aaa"
seq_df['EVENTS'] = np.array(['A', 'B', 'C', 'D'])
return seq_df
df_seq= my_df.groupby("ID").apply(my_udf)
I have simplified the udf function to non related to the input data. It is just creating a dataframe with two columns, one is ID, another is Array String Type. But I still got error:
Caused by: org.apache.spark.SparkException: Job aborted due to stage failure: Task 190 in stage 20.0 failed 4 times, most recent failure: Lost task 190.3 in stage 20.0 (TID 4817, 10.139.64.14, executor 1): org.apache.spark.api.python.PythonException: Traceback (most recent call last):
File "/databricks/spark/python/pyspark/worker.py", line 480, in main
process()
File "/databricks/spark/python/pyspark/worker.py", line 472, in process
serializer.dump_stream(out_iter, outfile)
File "/databricks/spark/python/pyspark/serializers.py", line 408, in dump_stream
timely_flush_timeout_ms=self.timely_flush_timeout_ms)
File "/databricks/spark/python/pyspark/serializers.py", line 215, in dump_stream
for batch in iterator:
File "/databricks/spark/python/pyspark/serializers.py", line 398, in init_stream_yield_batches
for series in iterator:
File "<string>", line 1, in <lambda>
File "/databricks/spark/python/pyspark/worker.py", line 136, in <lambda>
return lambda k, v: [(wrapped(k, v), to_arrow_type(return_type))]
File "/databricks/spark/python/pyspark/worker.py", line 124, in wrapped
result = f(key, pd.concat(value_series, axis=1))
File "/databricks/spark/python/pyspark/util.py", line 99, in wrapper
return f(*args, **kwargs)
File "<command-4469558475436012>", line 21, in count_transition
File "/databricks/python/lib/python3.7/site-packages/pandas/core/frame.py", line 3370, in __setitem__
self._set_item(key, value)
File "/databricks/python/lib/python3.7/site-packages/pandas/core/frame.py", line 3445, in _set_item
value = self._sanitize_column(key, value)
File "/databricks/python/lib/python3.7/site-packages/pandas/core/frame.py", line 3630, in _sanitize_column
value = sanitize_index(value, self.index, copy=False)
File "/databricks/python/lib/python3.7/site-packages/pandas/core/internals/construction.py", line 519, in sanitize_index
raise ValueError('Length of values does not match length of index')
ValueError: Length of values does not match length of index
Could anyone help me to check
In Odoo framework, i've all projects done and created already, now im stack on projects deadline, when i want to create a deadline of projet, the first commit and operation passes successfully, but the second gives me this error below :
Traceback (most recent call last):
File "D:\Odoo 11.0\server\odoo\fields.py", line 936, in __get__
value = record.env.cache.get(record, self)
File "D:\Odoo 11.0\server\odoo\api.py", line 960, in get
value = self._data[field][record.id][key]
KeyError: <odoo.api.Environment object at 0x000000000B34F550>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Odoo 11.0\server\odoo\http.py", line 647, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "D:\Odoo 11.0\server\odoo\http.py", line 307, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "D:\Odoo 11.0\server\odoo\tools\pycompat.py", line 87, in reraise
raise value
File "D:\Odoo 11.0\server\odoo\http.py", line 689, in dispatch
result = self._call_function(**self.params)
File "D:\Odoo 11.0\server\odoo\http.py", line 339, in _call_function
return checked_call(self.db, *args, **kwargs)
File "D:\Odoo 11.0\server\odoo\service\model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "D:\Odoo 11.0\server\odoo\http.py", line 332, in checked_call
result = self.endpoint(*a, **kw)
File "D:\Odoo 11.0\server\odoo\http.py", line 933, in __call__
return self.method(*args, **kw)
File "D:\Odoo 11.0\server\odoo\http.py", line 512, in response_wrap
response = f(*args, **kw)
File "D:\Odoo 11.0\server\odoo\addons\web\controllers\main.py", line 872, in search_read
return self.do_search_read(model, fields, offset, limit, domain, sort)
File "D:\Odoo 11.0\server\odoo\addons\web\controllers\main.py", line 894, in do_search_read
offset=offset or 0, limit=limit or False, order=sort or False)
File "D:\Odoo 11.0\server\odoo\models.py", line 4169, in search_read
result = records.read(fields)
File "D:\Odoo 11.0\server\odoo\models.py", line 2535, in read
values[name] = field.convert_to_read(record[name], record, use_name_get)
File "D:\Odoo 11.0\server\odoo\models.py", line 4688, in __getitem__
return self._fields[key].__get__(self, type(self))
File "D:\Odoo 11.0\server\odoo\fields.py", line 940, in __get__
self.determine_value(record)
File "D:\Odoo 11.0\server\odoo\fields.py", line 1051, in determine_value
self.compute_value(recs)
File "D:\Odoo 11.0\server\odoo\fields.py", line 1007, in compute_value
self._compute_value(records)
File "D:\Odoo 11.0\server\odoo\fields.py", line 998, in _compute_value
getattr(records, self.compute)()
File "D:\Odoo 11.0\server\odoo\addons\dev\models\delais.py", line 24, in _delai_arret
domaine = ('project_ids', '=', self.project_ids).id
File "D:\Odoo 11.0\server\odoo\fields.py", line 934, in __get__
record.ensure_one()
File "D:\Odoo 11.0\server\odoo\models.py", line 4296, in ensure_one
raise ValueError("Expected singleton: %s" % self)
ValueError: Expected singleton: delais.delais(2, 18)
And this is the function which calculate the sum of missions number of each project, in this function i got the error. Please i didn't figure out where is the problem exactly, help me to get rid of this please, thank's for your support.
def _delai_arret(self):
domaine = ('project_ids', '=', self.project_ids).id
dict = self.env['mission.mission'].search_read([domaine], ['nbr_mission'])
# print(dict)
if not dict:
pass
else:
somme = 0
for key in dict:
# print(key['nbr_mission'])
somme = somme + key['nbr_mission'] / 30
# print('la somme est : {somme}')
self.delai_arr_mois = somme
# print(somme)