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

[16.0][MIG] dbfilter_from_header #2425

Merged
merged 18 commits into from
Dec 30, 2022

Conversation

carmenbianca
Copy link
Member

No description provided.

hbrunn and others added 17 commits October 13, 2022 16:09
Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>
Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>
Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>
Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>
Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>
[MIG] migrate dbfilter_from_header to 10.0

I have also removed the ability to use HTTP_X_OPENERP_DBFILTER

Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>
updates were made in OCA#1137 by @TimLai125

and small lint fixes by @yelizariev

Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>
Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>
Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>

[UPD] Update dbfilter_from_header.pot

Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>

[UPD] README.rst

Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>
Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>
Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>
Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>

[UPD] Update dbfilter_from_header.pot

Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: server-tools-13.0/server-tools-13.0-dbfilter_from_header
Translate-URL: https://translation.odoo-community.org/projects/server-tools-13-0/server-tools-13-0-dbfilter_from_header/
Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>
Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>

[UPD] Update dbfilter_from_header.pot

Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>

[UPD] README.rst

Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>
Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>

[UPD] Update dbfilter_from_header.pot

Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>

[UPD] README.rst

Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>
Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>
@oca-clabot
Copy link

Hey @carmenbianca, thank you for your Pull Request.

It looks like some users haven't signed our Contributor License Agreement, yet.
You can read and sign our full Contributor License Agreement here: https://odoo-community.org/page/cla
Here is a list of the users:

Appreciation of efforts,
OCA CLAbot

@carmenbianca
Copy link
Member Author

Not making decent progress on this. The signature of db_filter was changed from db_filter(dbs, httprequest=None) to db_filter(dbs, host=None), where host is (for example) 'localhost:8069'.

The upstream db_filter code contains this snippet:

    if config['dbfilter']:
        #        host
        #     -----------
        # www.example.com:80
        #     -------
        #     domain
        if host is None:
            host = request.httprequest.environ.get('HTTP_HOST', '')

If I pause my debugger on the first line and execute request.httprequest, I get the following traceback:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/var/home/coopiteasy/.virtualenvs/odoo16/lib64/python3.10/site-packages/werkzeug/local.py", line 432, in __get__
    obj = instance._get_current_object()
  File "/var/home/coopiteasy/.virtualenvs/odoo16/lib64/python3.10/site-packages/werkzeug/local.py", line 554, in _get_current_object
    return self.__local()  # type: ignore
  File "/var/home/coopiteasy/.virtualenvs/odoo16/lib64/python3.10/site-packages/werkzeug/local.py", line 226, in _lookup
    raise RuntimeError("object unbound")
RuntimeError: object unbound

The request object is <LocalProxy> (its repr is ''). Attempting to do anything with this object results in the above traceback.

So the Odoo code seems broken to me in any scenario where host is None.

So of course, when I do httprequest = http.request.httprequest in override.py, I get a similar traceback:

Traceback (most recent call last):
  File "/home/odoo16/venv/lib/python3.8/site-packages/werkzeug/serving.py", line 306, in run_wsgi
    execute(self.server.app)
  File "/home/odoo16/venv/lib/python3.8/site-packages/werkzeug/serving.py", line 294, in execute
    application_iter = app(environ, start_response)
  File "/home/odoo16/src/odoo/odoo/http.py", line 1942, in __call__
    request = Request(httprequest)
  File "/home/odoo16/src/odoo/odoo/http.py", line 1101, in __init__
    self.session, self.db = self._get_session_and_dbname()
  File "/home/odoo16/src/odoo/odoo/http.py", line 1133, in _get_session_and_dbname
    if session.db and db_filter([session.db], host=host):
  File "/home/odoo16/src/oca/server-tools/dbfilter_from_header/override.py", line 17, in db_filter
    print(http.request)
  File "/home/odoo16/venv/lib/python3.8/site-packages/werkzeug/local.py", line 367, in <lambda>
    __str__ = lambda x: str(x._get_current_object())
  File "/home/odoo16/venv/lib/python3.8/site-packages/werkzeug/local.py", line 307, in _get_current_object
    return self.__local()
  File "/home/odoo16/venv/lib/python3.8/site-packages/werkzeug/local.py", line 137, in _lookup
    raise RuntimeError("object unbound")
RuntimeError: object unbound - - -

The request objects that we actually want is in the process of being created in line 1101 above (Request's __init__ function). The httprequest object we want already exists in the request object's __init__.

Not sure what the correct course of action is to tackle this problem.

@nilshamerlinck
Copy link
Contributor

nilshamerlinck commented Oct 17, 2022

Hello @carmenbianca I faced this issue as well. Worked around it here. Not very elegant, but works 😅 Thoughts welcome!

@Entrepreneur-AJ
Copy link

Just tested on a virsh setup seems to be working well, mention me when your ready for it to be merged and (providing there's no drastic changes) i will code review it. Should be able to get OCA Bot to kick in then.

Signed-off-by: Carmen Bianca Bakker <carmen@coopiteasy.be>
@carmenbianca carmenbianca force-pushed the 16.0-mig-dbfilter_from_header branch from 4a24a5b to e6cec53 Compare November 15, 2022 14:29
@carmenbianca carmenbianca marked this pull request as ready for review November 15, 2022 14:47
@carmenbianca
Copy link
Member Author

Squashed the last commit. Just tested this as well → it works. Ready for merging as far as I'm concerned.

@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@skaag
Copy link

skaag commented Nov 18, 2022

Tested this in a QA environment with multiple instances of Odoo 16 and it works well 🤙
(to clarify: A single install of Odoo 16 on a single server, with multiple tenants, via db_filter)

@Entrepreneur-AJ Entrepreneur-AJ mentioned this pull request Dec 19, 2022
33 tasks
@dreispt
Copy link
Member

dreispt commented Dec 30, 2022

/ocabot merge nobump

@OCA-git-bot
Copy link
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 16.0-ocabot-merge-pr-2425-by-dreispt-bump-nobump, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 284c135 into OCA:16.0 Dec 30, 2022
@OCA-git-bot
Copy link
Contributor

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

@StefanRijnhart
Copy link
Member

/ocabot migration dbfilter_from_header

@OCA-git-bot OCA-git-bot added this to the 16.0 milestone Jan 13, 2023
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.