Skip to content

Conversation

@BhaveshHeliconia
Copy link
Contributor

@BhaveshHeliconia BhaveshHeliconia commented Sep 4, 2025

  • issue :-
    The module extended project.project with _rec_names_search = ["key", "name", "id"].
    Including "id" in _rec_names_search caused SQL errors when users searched with text values (e.g., "inter").

    Odoo generated invalid queries like:
    "project_project"."id" = 'inter'
    which failed because id is an integer field.

  • Steps to Reproduce the Error :-

  1. Go to Timesheets → Tree/List View.
  2. Add a custom filter:
    Field: Project
    Operator: is equal to
    Value: any string (e.g., "inter")
    Apply the filter.

You will get the following error:
ERROR: invalid input syntax for type integer: "inter"
LINE 1: ...->>'en_US' = 'inter')) OR ("project_project"."id" = 'inter')) AN...

Odoo.-.My.Timesheets.mp4

@BhaveshHeliconia
Copy link
Contributor Author

Blocked by : #1562 Once that PR is merged, the CI will be green.

@BhaveshHeliconia
Copy link
Contributor Author

@AaronHForgeFlow @yajo , the PR is ready for review at your convenience.

Copy link

@AaronHForgeFlow AaronHForgeFlow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Code LGTM

Comment on lines +16 to +34
args = list(args or [])
search_domain = []

if name:
search_domain = [
("key", operator, name),
("name", operator, name),
]
if name.isdigit():
search_domain.append(("id", "=", int(name)))

if len(search_domain) > 1:
domain = ["|"] * (len(search_domain) - 1) + search_domain
else:
domain = search_domain
else:
domain = []

return self._search(domain + args, limit=limit, access_rights_uid=name_get_uid)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: IIUC, you don't need to redo everything that _name_search will do automatically when _rec_names_search is properly configured.

Besides, overriding without calling super() is a general bad practice.

Check this please:

Suggested change
args = list(args or [])
search_domain = []
if name:
search_domain = [
("key", operator, name),
("name", operator, name),
]
if name.isdigit():
search_domain.append(("id", "=", int(name)))
if len(search_domain) > 1:
domain = ["|"] * (len(search_domain) - 1) + search_domain
else:
domain = search_domain
else:
domain = []
return self._search(domain + args, limit=limit, access_rights_uid=name_get_uid)
args = list(args or [])
if name.isdigit():
args.insert(0, ("id", "=", int(name)))
return super()._name_search(name, args, operator, limit, name_get_uid)

@yajo
Copy link
Member

yajo commented Sep 26, 2025

Oh, and please add a test. Thanks!

@github-actions
Copy link

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Jan 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale PR/Issue without recent activity, it'll be soon closed automatically.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants