Skip to content

Commit

Permalink
Merge 0a18c9b into d260411
Browse files Browse the repository at this point in the history
  • Loading branch information
moylop260 committed May 20, 2022
2 parents d260411 + 0a18c9b commit e81c321
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pylint_odoo/checkers/no_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@
'str-format-used',
settings.DESC_DFLT
),
'E%d06' % settings.BASE_NOMODULE_ID: (
'Use of `requests.%s` method without timeout. '
'It could wait for a long time',
'request-without-timeout',
settings.DESC_DFLT
),
'C%d01' % settings.BASE_NOMODULE_ID: (
'One of the following authors must be present in manifest: %s',
'manifest-required-author',
Expand Down Expand Up @@ -589,11 +595,13 @@ def visit_print(self, node):
'translation-contains-variable',
'print-used', 'translation-positional-used',
'str-format-used', 'context-overridden',
'request-without-timeout',
)
def visit_call(self, node):
infer_node = utils.safe_infer(node.func)
if utils.is_builtin_object(infer_node) and infer_node.name == 'print':
self.add_message('print-used', node=node)
# TODO: Add self.linter.is_message_enabled() for each section
if ('fields' == self.get_func_lib(node.func) and
isinstance(node.parent, astroid.Assign) and
isinstance(node.parent.parent, astroid.ClassDef)):
Expand Down Expand Up @@ -750,6 +758,20 @@ def visit_call(self, node):
if self._check_sql_injection_risky(node):
self.add_message('sql-injection', node=node)

# requests calls
func_name = self.get_func_name(node.func)
if func_name in ('get', 'post'):
if self.get_func_lib(node.func) == 'requests':
# TODO: Get imported node renamed
for argument in misc.join_node_args_kwargs(node):
if not isinstance(argument, astroid.Keyword):
continue
if argument.arg == 'timeout':
break
else:
self.add_message(
'request-without-timeout', node=node, args=(func_name,))

@utils.check_messages(
'license-allowed', 'manifest-author-string', 'manifest-deprecated-key',
'manifest-required-author', 'manifest-required-key',
Expand Down
2 changes: 2 additions & 0 deletions pylint_odoo/test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
'po-msgstr-variables': 6,
'print-used': 1,
'redundant-modulename-xml': 1,
# TODO: update after fixing other TODO :)
'request-without-timeout': 2,
'rst-syntax-error': 2,
'sql-injection': 21,
'str-format-used': 3,
Expand Down
20 changes: 20 additions & 0 deletions pylint_odoo/test_repo/broken_module/models/broken_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import psycopg2
from psycopg2 import sql
from psycopg2.sql import SQL, Identifier
import requests
from requests import post, get
from requests import post as post_r, get as get_r

from openerp import fields, models, _
from openerp.exceptions import Warning as UserError
Expand All @@ -16,6 +19,7 @@


other_field = fields.Char()
import requests


def function_no_method():
Expand Down Expand Up @@ -537,6 +541,22 @@ def func(self, a):
length = len(a)
return length

def requests_test(self):
# request without timeout
requests.post('http://localhost')
requests.get('http://localhost')
post('http://localhost')
get('http://localhost')
post_r('http://localhost')
get_r('http://localhost')

# Valid cases
requests.post('http://localhost', timeout=10)
requests.get('http://localhost', timeout=10)
post('http://localhost', timeout=10)
get('http://localhost', timeout=10)
post_r('http://localhost', timeout=10)
get_r('http://localhost', timeout=10)

class NoOdoo(object):
length = 0
Expand Down

0 comments on commit e81c321

Please sign in to comment.