Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0] [FIX] website_require_login: hidden exception #1036

Merged

Conversation

renda-dev
Copy link
Contributor

@renda-dev renda-dev commented Mar 14, 2024

Fixed an issue where if an exception has been raised, it would try to access a closed cursor, causing the disconnection and re-connection from the website, totally hiding the exception message.

Traceback (partial):

File "/opt/odoo/custom/src/odoo/odoo/service/wsgi_server.py", line 113, in application
  return application_unproxied(environ, start_response)
File "/opt/odoo/custom/src/odoo/odoo/service/wsgi_server.py", line 88, in application_unproxied
  result = odoo.http.root(environ, start_response)
File "/opt/odoo/custom/src/odoo/odoo/http.py", line 1341, in __call__
  return self.dispatch(environ, start_response)
File "/opt/odoo/custom/src/odoo/odoo/http.py", line 1307, in __call__
  return self.app(environ, start_wrapped)
File "/usr/local/lib/python3.8/site-packages/werkzeug/middleware/shared_data.py", line 220, in __call__
  return self.app(environ, start_response)
File "/opt/odoo/custom/src/odoo/odoo/http.py", line 1530, in dispatch
  result = ir_http._dispatch()
File "/opt/odoo/custom/src/website/website_require_login/models/ir_http.py", line 21, in _dispatch
  if request.uid == website.user_id.id:
File "/opt/odoo/custom/src/odoo/odoo/fields.py", line 2494, in __get__
  return super().__get__(records, owner)
File "/opt/odoo/custom/src/odoo/odoo/fields.py", line 1020, in __get__
  recs._fetch_field(self)
File "/opt/odoo/custom/src/odoo/odoo/models.py", line 3085, in _fetch_field
  self._read(fnames)
File "/opt/odoo/custom/src/odoo/odoo/models.py", line 3152, in _read
  cr.execute(query_str, params + [sub_ids])
File "<decorator-gen-5>", line 2, in execute
  
File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 101, in check
  return f(self, *args, **kwargs)
File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 301, in execute
  res = self._obj.execute(query, params)
psycopg2.errors.InFailedSqlTransaction: current transaction is aborted, commands ignored until end of transaction block

pre-commit is fixed in: #1037

@renda-dev renda-dev force-pushed the 14.0-fix-website_require_login-hide-exception branch 2 times, most recently from 36a0ddc to f3249ff Compare March 15, 2024 09:32
Copy link
Contributor

@francesco-ooops francesco-ooops left a comment

Choose a reason for hiding this comment

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

Functional ok!

Copy link

@aleuffre aleuffre left a comment

Choose a reason for hiding this comment

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

Code review, LGTM

@francesco-ooops
Copy link
Contributor

@pedrobaeza good for you?

@pedrobaeza pedrobaeza added this to the 14.0 milestone Mar 19, 2024
# it means that an exception has been
# raised and the cursor is currently closed
try:
user_id = website.user_id
Copy link
Member

Choose a reason for hiding this comment

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

Incorrect variable name:

Suggested change
user_id = website.user_id
user = website.user_id

# raised and the cursor is currently closed
try:
user_id = website.user_id
except Exception:
Copy link
Member

Choose a reason for hiding this comment

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

Too broad exception. Put a stricter restriction for the use case.

user_id = website.user_id
except Exception:
return res

Copy link
Member

Choose a reason for hiding this comment

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

It's better to not add empty lines inside a method, as its value is very limited and makes you scroll more.

@renda-dev renda-dev force-pushed the 14.0-fix-website_require_login-hide-exception branch from f3249ff to 1963e8c Compare March 20, 2024 08:26
@renda-dev
Copy link
Contributor Author

Thanks for the feedback @pedrobaeza, I've addressed all of the issues, could you please give it another look?

Copy link
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

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

/ocabot merge patch

@OCA-git-bot
Copy link
Contributor

This PR looks fantastic, let's merge it!
Prepared branch 14.0-ocabot-merge-pr-1036-by-pedrobaeza-bump-patch, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 252a02b into OCA:14.0 Mar 20, 2024
5 of 7 checks passed
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 399ca0d. Thanks a lot for contributing to OCA. ❤️

@renda-dev renda-dev deleted the 14.0-fix-website_require_login-hide-exception branch March 20, 2024 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants