Skip to content

Commit

Permalink
[FIX] Use resp.get() to prevent KeyError tinyerp#9
Browse files Browse the repository at this point in the history
  • Loading branch information
arkhan committed Jan 8, 2023
1 parent 09496ff commit 59d95ec
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions odooly.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Author: Florent Xicluna
"""
import _ast
import atexit
import csv
import functools
Expand All @@ -16,19 +17,19 @@
import time
import traceback

import _ast

PY2 = sys.version_info[0] == 2
if not PY2: # Python 3
from configparser import ConfigParser
from threading import current_thread
from urllib.request import Request, urlopen
from xmlrpc.client import Fault, ServerProxy, MININT, MAXINT
from xmlrpc.client import MAXINT, MININT, Fault, ServerProxy
else: # Python 2
from ConfigParser import SafeConfigParser as ConfigParser
from threading import currentThread as current_thread

from ConfigParser import SafeConfigParser as ConfigParser
from urllib2 import Request, urlopen
from xmlrpclib import Fault, ServerProxy, MININT, MAXINT
from xmlrpclib import MAXINT, MININT, Fault, ServerProxy

try:
import requests
Expand Down Expand Up @@ -166,7 +167,6 @@ def _dict_to_list(self, rowdict):
for cell in rowlst
]


else: # Python 3
basestring = str
int_types = int
Expand Down Expand Up @@ -441,7 +441,6 @@ def http_post(url, data, headers={"Content-Type": "application/json"}):
resp = requests.post(url, data=data, headers=headers)
return resp.json()


else:

def http_post(url, data, headers={"Content-Type": "application/json"}):
Expand All @@ -455,12 +454,12 @@ def dispatch_jsonrpc(url, service_name, method, args):
"jsonrpc": "2.0",
"method": "call",
"params": {"service": service_name, "method": method, "args": args},
"id": "%04x%010x" % (os.getpid(), (int(time.time() * 1e6) % 2 ** 40)),
"id": "%04x%010x" % (os.getpid(), (int(time.time() * 1e6) % 2**40)),
}
resp = http_post(url, json.dumps(data).encode("ascii"))
if resp.get("error"):
raise ServerError(resp["error"])
return resp["result"]
return resp.get("result")


class partial(functools.partial):
Expand Down Expand Up @@ -544,13 +543,13 @@ def wrapper(self, *args):
class Env(object):
"""An environment wraps data for Odoo models and records:
- :attr:`db_name`, the current database;
- :attr:`uid`, the current user id;
- :attr:`context`, the current context dictionary.
- :attr:`db_name`, the current database;
- :attr:`uid`, the current user id;
- :attr:`context`, the current context dictionary.
To retrieve an instance of ``some.model``:
To retrieve an instance of ``some.model``:
>>> env["some.model"]
>>> env["some.model"]
"""

name = uid = user = None
Expand Down Expand Up @@ -1953,7 +1952,12 @@ def _set_external_id(self, xml_id):
if self.env["ir.model.data"].search(domain):
raise ValueError("ID %r collides with another entry" % xml_id)
self.env["ir.model.data"].create(
{"model": self._name, "res_id": self.id, "module": mod, "name": name,}
{
"model": self._name,
"res_id": self.id,
"module": mod,
"name": name,
}
)

def __getattr__(self, attr):
Expand Down

0 comments on commit 59d95ec

Please sign in to comment.