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

[FIX] website : fix authenticate archived visitor #40199

Closed

Conversation

dbeguin
Copy link
Contributor

@dbeguin dbeguin commented Nov 13, 2019

If a visitor logs in (and has a visitor_id in his cookie), the partner will be
linked to the visitor. If, after 1 week, the visitor tries to connect again
with a different session (or another visitor_id in cookies), the authenticate
will crash because:

  • _cron_archive_visitors applies on visitor inactive since at least a week
  • there can be only one visitor per partner (sql constraint)
  • The visitor linked to the partner is not retrieved (because archived) and
    we try to link the partner to a new visitor.

Further than that, if the visitor is archived and the linked partner wants to
login again with a new visitor_id, we should :

  • reactivate the previous visitor,
  • copy history from newest to previous one
  • delete the newest one

(last two points were already done before this commit).

This PR also fixes and simplifies the time_statistics computation.
As time_connection_datetime is always set and in the depends, no need to read
values before looping, the data is already fetched in memory. We can than
use directly the value for each visitor in self.

Task ID: 2120464

@dbeguin dbeguin force-pushed the 13.0-fix-visitor-authenticate-archive-dbe branch from 6c5520f to 0c82243 Compare November 13, 2019 13:47
@dbeguin dbeguin force-pushed the 13.0-fix-visitor-authenticate-archive-dbe branch from 0c82243 to 8cc4d93 Compare November 13, 2019 13:52
@dbeguin dbeguin force-pushed the 13.0-fix-visitor-authenticate-archive-dbe branch from 8cc4d93 to dc595c4 Compare November 13, 2019 13:52
@C3POdoo C3POdoo added the RD research & development, internal work label Nov 13, 2019
@robodoo robodoo added the CI 🤖 Robodoo has seen passing statuses label Nov 13, 2019
Copy link
Contributor

@awa-odoo awa-odoo left a comment

Choose a reason for hiding this comment

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

Hi.

Blup.

Bye.

addons/website/models/website_visitor.py Show resolved Hide resolved
visitor_sudo.website_track_ids.write({'visitor_id': partner_visitor.id})
visitor_sudo.unlink()
# Reactivate the older Visitor & Update visitor's Cookie (TODO: check if necessary (maybe done in _handle_webpage_dispatch)
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. I don't like that TODO, can you actually check?
  2. It's unclear here that visitors are archived by a cron, should be explained in the docstring AND in the commit message
  3. I don't see any cookie update, the comment is a little confusing
  4. I attach an image related to all points above

brain

@dbeguin dbeguin force-pushed the 13.0-fix-visitor-authenticate-archive-dbe branch from dc595c4 to 29a9526 Compare November 19, 2019 13:43
@robodoo robodoo removed the CI 🤖 Robodoo has seen passing statuses label Nov 19, 2019
@dbeguin dbeguin force-pushed the 13.0-fix-visitor-authenticate-archive-dbe branch from 29a9526 to 36dc88b Compare November 19, 2019 13:47
@dbeguin dbeguin force-pushed the 13.0-fix-visitor-authenticate-archive-dbe branch from 36dc88b to b6d70f1 Compare November 19, 2019 13:48
@robodoo robodoo added the CI 🤖 Robodoo has seen passing statuses label Nov 19, 2019
Copy link
Contributor

@awa-odoo awa-odoo left a comment

Choose a reason for hiding this comment

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

Small readability comment and one remark.

Also, in that commit: "[FIX] website : fix authenticate archived visitor":
You should make bullet points with the second paragraph.
Makes it easier to see what's already done when you say "last two points were already done".

visitor_sudo.website_track_ids.write({'visitor_id': partner_visitor.id})
visitor_sudo.unlink()
# Reactivate the older Visitor
Copy link
Contributor

Choose a reason for hiding this comment

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

# Reactivate the archived visitor (most likely archived by the cron for inactivity reasons)

addons/website/models/res_users.py Show resolved Hide resolved
@dbeguin dbeguin force-pushed the 13.0-fix-visitor-authenticate-archive-dbe branch from b6d70f1 to b512fc6 Compare November 20, 2019 12:46
@robodoo robodoo removed the CI 🤖 Robodoo has seen passing statuses label Nov 20, 2019
@dbeguin dbeguin force-pushed the 13.0-fix-visitor-authenticate-archive-dbe branch from b512fc6 to bf449d1 Compare November 20, 2019 13:20
@dbeguin
Copy link
Contributor Author

dbeguin commented Nov 20, 2019

@awa-odoo : tests added for this particular flow.
Comments applied or answered !
Bisous!

@robodoo robodoo added the CI 🤖 Robodoo has seen passing statuses label Nov 20, 2019
Copy link
Contributor

@awa-odoo awa-odoo left a comment

Choose a reason for hiding this comment

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

blork test review

addons/website/tests/test_website_visitor.py Outdated Show resolved Hide resolved
})
partner_demo = self.env.ref('base.partner_demo')
old_visitor.partner_id = partner_demo.id
partner_demo.visitor_ids = [(6, 0, [old_visitor.id])] # TODO DBE : To remove in Master (13.1) after visitor_ids field declaration master fix
Copy link
Contributor

Choose a reason for hiding this comment

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

change to [4, old_visitor.id]

Copy link
Contributor Author

@dbeguin dbeguin Nov 21, 2019

Choose a reason for hiding this comment

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

I will remove this anyway after forward port (And I need to flush if I use [4, id]) sooooo

addons/website/tests/test_website_visitor.py Outdated Show resolved Hide resolved
addons/website/tests/test_website_visitor.py Outdated Show resolved Hide resolved
if self.target_visitor:
return self.target_visitor
else:
return self.Visitor._create_visitor() if force_create else self.Visitor
Copy link
Contributor

Choose a reason for hiding this comment

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

As you define self.target_visitor just above, can you reach the else case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah indeed, oopsy (I defined it in the setup originally)

addons/website/tests/test_website_visitor.py Outdated Show resolved Hide resolved
addons/website/tests/test_website_visitor.py Outdated Show resolved Hide resolved
@robodoo
Copy link
Contributor

robodoo commented Dec 2, 2019

Merge method set to rebase and fast-forward

@robodoo robodoo added the CI 🤖 Robodoo has seen passing statuses label Dec 2, 2019
robodoo pushed a commit that referenced this pull request Dec 2, 2019
This commit fixes the visitor's time_statistics computation. When creating a
new visitor, last connection datetime is not set, so it's not retrieved in the
search_read and crash at search_read_result[visitor.id].

This fix also speeds up and simplifies the time_statistics computation.
As time_connection_datetime is always set (for already created visitor) and in
the depends, no need to read values before looping, the data is already fetched
in memory. We can then use directly the value for each visitor in self.

Task ID: 2120464
PR #40199
robodoo pushed a commit that referenced this pull request Dec 2, 2019
If a visitor logs in (and has a visitor_id in his cookie), the partner will be
linked to the visitor. If, after 1 week, the visitor tries to connect again
with a different session (or another visitor_id in cookies), the authenticate
will crash because

  * _cron_archive_visitors applies on visitor inactive since at least a week
  * there can be only one visitor per partner (sql constraint)
  * the visitor linked to the partner is not retrieved (because archived) and
  we try to link the partner to a new visitor.

Further than that, if the visitor is archived and the linked partner wants to
login again with a new visitor_id, we should

  * reactivate the previous visitor,
  * copy history from newest to previous one,
  * delete the newest one

Note that last two points were already done before this commit.

Task ID: 2120464
PR #40199
Fixes #40077
Fixes #40301

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
@robodoo robodoo closed this Dec 2, 2019
@robodoo robodoo temporarily deployed to merge December 2, 2019 18:06 Inactive
dbeguin added a commit to odoo-dev/odoo that referenced this pull request Dec 3, 2019
If a visitor logs in (and has a visitor_id in his cookie), the partner will be
linked to the visitor. If, after 1 week, the visitor tries to connect again
with a different session (or another visitor_id in cookies), the authenticate
will crash because

  * _cron_archive_visitors applies on visitor inactive since at least a week
  * there can be only one visitor per partner (sql constraint)
  * the visitor linked to the partner is not retrieved (because archived) and
  we try to link the partner to a new visitor.

Further than that, if the visitor is archived and the linked partner wants to
login again with a new visitor_id, we should

  * reactivate the previous visitor,
  * copy history from newest to previous one,
  * delete the newest one

Note that last two points were already done before this commit.

Task ID: 2120464
PR odoo#40199
Fixes odoo#40077
Fixes odoo#40301

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
robodoo pushed a commit that referenced this pull request Dec 3, 2019
If a visitor logs in (and has a visitor_id in his cookie), the partner will be
linked to the visitor. If, after 1 week, the visitor tries to connect again
with a different session (or another visitor_id in cookies), the authenticate
will crash because

  * _cron_archive_visitors applies on visitor inactive since at least a week
  * there can be only one visitor per partner (sql constraint)
  * the visitor linked to the partner is not retrieved (because archived) and
  we try to link the partner to a new visitor.

Further than that, if the visitor is archived and the linked partner wants to
login again with a new visitor_id, we should

  * reactivate the previous visitor,
  * copy history from newest to previous one,
  * delete the newest one

Note that last two points were already done before this commit.

Task ID: 2120464
PR #40199
Fixes #40077
Fixes #40301

closes #41220

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
fw-bot pushed a commit to odoo-dev/odoo that referenced this pull request Dec 3, 2019
If a visitor logs in (and has a visitor_id in his cookie), the partner will be
linked to the visitor. If, after 1 week, the visitor tries to connect again
with a different session (or another visitor_id in cookies), the authenticate
will crash because

  * _cron_archive_visitors applies on visitor inactive since at least a week
  * there can be only one visitor per partner (sql constraint)
  * the visitor linked to the partner is not retrieved (because archived) and
  we try to link the partner to a new visitor.

Further than that, if the visitor is archived and the linked partner wants to
login again with a new visitor_id, we should

  * reactivate the previous visitor,
  * copy history from newest to previous one,
  * delete the newest one

Note that last two points were already done before this commit.

Task ID: 2120464
PR odoo#40199
Fixes odoo#40077
Fixes odoo#40301

Original-signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
X-original-commit: 53a6bed
robodoo pushed a commit that referenced this pull request Dec 4, 2019
If a visitor logs in (and has a visitor_id in his cookie), the partner will be
linked to the visitor. If, after 1 week, the visitor tries to connect again
with a different session (or another visitor_id in cookies), the authenticate
will crash because

  * _cron_archive_visitors applies on visitor inactive since at least a week
  * there can be only one visitor per partner (sql constraint)
  * the visitor linked to the partner is not retrieved (because archived) and
  we try to link the partner to a new visitor.

Further than that, if the visitor is archived and the linked partner wants to
login again with a new visitor_id, we should

  * reactivate the previous visitor,
  * copy history from newest to previous one,
  * delete the newest one

Note that last two points were already done before this commit.

Task ID: 2120464
PR #40199
Fixes #40077
Fixes #40301

closes #41273

Original-signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
X-original-commit: 53a6bed
Signed-off-by: David Beguin <dbeguin@users.noreply.github.com>
@fw-bot fw-bot deleted the 13.0-fix-visitor-authenticate-archive-dbe branch December 16, 2019 18:46
@dbeguin
Copy link
Contributor Author

dbeguin commented Jan 22, 2020

@d-fence or @KangOl : This PR seems not to be forward ported yet to master. Is it normal ?

@dbeguin
Copy link
Contributor Author

dbeguin commented Jan 22, 2020

Ah, apparently, a part of this PR have been removed in the FW PR. strange..

dbeguin added a commit to odoo-dev/odoo that referenced this pull request Jan 22, 2020
This commit fixes the visitor's time_statistics computation. When creating a
new visitor, last connection datetime is not set, so it's not retrieved in the
search_read and crash at search_read_result[visitor.id].

This fix also speeds up and simplifies the time_statistics computation.
As time_connection_datetime is always set (for already created visitor) and in
the depends, no need to read values before looping, the data is already fetched
in memory. We can then use directly the value for each visitor in self.

Task ID: 2120464
PR odoo#40199
robodoo pushed a commit that referenced this pull request Jan 22, 2020
This commit fixes the visitor's time_statistics computation. When creating a
new visitor, last connection datetime is not set, so it's not retrieved in the
search_read and crash at search_read_result[visitor.id].

This fix also speeds up and simplifies the time_statistics computation.
As time_connection_datetime is always set (for already created visitor) and in
the depends, no need to read values before looping, the data is already fetched
in memory. We can then use directly the value for each visitor in self.

Task ID: 2120464
PR #40199

closes #43758

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
fw-bot pushed a commit to odoo-dev/odoo that referenced this pull request Jan 22, 2020
This commit fixes the visitor's time_statistics computation. When creating a
new visitor, last connection datetime is not set, so it's not retrieved in the
search_read and crash at search_read_result[visitor.id].

This fix also speeds up and simplifies the time_statistics computation.
As time_connection_datetime is always set (for already created visitor) and in
the depends, no need to read values before looping, the data is already fetched
in memory. We can then use directly the value for each visitor in self.

Task ID: 2120464
PR odoo#40199

X-original-commit: 1f0c9f2
robodoo pushed a commit that referenced this pull request Jan 22, 2020
This commit fixes the visitor's time_statistics computation. When creating a
new visitor, last connection datetime is not set, so it's not retrieved in the
search_read and crash at search_read_result[visitor.id].

This fix also speeds up and simplifies the time_statistics computation.
As time_connection_datetime is always set (for already created visitor) and in
the depends, no need to read values before looping, the data is already fetched
in memory. We can then use directly the value for each visitor in self.

Task ID: 2120464
PR #40199

closes #43780

X-original-commit: 1f0c9f2
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
@actonsys
Copy link

actonsys commented Feb 7, 2020

I think this following error is related to this PR, @dbeguin .
This is happening on production mode and it's been thrown several times when different users are trying to acces the website. If reload the page, the webpage comes back to normal, but after a while, the same issue.

2020-02-07 05:02:44,643 31740 ERROR DB odoo.sql_db: bad query: INSERT INTO "website_track" ("id", "page_id", "url", "visit_datetime", "visitor_id") VALUES (nextval('website_track_id_seq'), 4, 'https://www.WEBSITEXXX', '2020-02-07 05:02:44.638207', 43) RETURNING id
ERROR: could not serialize access due to concurrent update
CONTEXT: SQL statement "SELECT 1 FROM ONLY "public"."website_visitor" x WHERE "id" OPERATOR(pg_catalog.=) $1 FOR KEY SHARE OF x"

@tde-banana-odoo
Copy link
Contributor

We will have a look. Thanks for pointing it out !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI 🤖 Robodoo has seen passing statuses RD research & development, internal work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants