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

[12.0][FIX] base: don't create user_admin if already exists #1779

Conversation

MiquelRForgeFlow
Copy link
Contributor

Fixes #1766

--
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

@pedrobaeza
Copy link
Member

Use ON CONFLICT DO NOTHING instead.

@MiquelRForgeFlow MiquelRForgeFlow force-pushed the 12.0-fix-base-not-insert-admin_user-if-already-exist branch from 9d8a0b5 to b182933 Compare March 15, 2019 18:49
@MiquelRForgeFlow
Copy link
Contributor Author

Done

@pedrobaeza
Copy link
Member

But the question in the issue remains: if this is not added by core, if we do this, the record can point to other thing that it's not even the same model.

@MiquelRForgeFlow MiquelRForgeFlow changed the title [12.0][FIX] base: don't create user_admin is already exists [12.0][FIX] base: don't create user_admin if already exists Mar 29, 2019
@StefanRijnhart
Copy link
Member

Agreed. Would be very interesting to know how this xml entry ended up there. Was it an earlier, failed run of the pre migration script? (but the rest of the script does not look reentrant either)

@pedrobaeza
Copy link
Member

@mreficent can you answer?

@MiquelRForgeFlow
Copy link
Contributor Author

MiquelRForgeFlow commented Apr 23, 2019

No idea. @yann-papouin or @kenji-autotest should answer haha
But my two cents are YES, it seems a a rerun of a failed pre-migration.

@pedrobaeza
Copy link
Member

OK, then unless we demonstrate this is a real issue, this doesn't serve, and starting to put safeguards everywhere is not the best option IMO.

@pedrobaeza
Copy link
Member

I believe this happened due to #1879, so closing for now while not proofs about it.

@pedrobaeza pedrobaeza closed this Jun 15, 2019
@MiquelRForgeFlow MiquelRForgeFlow deleted the 12.0-fix-base-not-insert-admin_user-if-already-exist branch June 17, 2019 08:12
@MiquelRForgeFlow MiquelRForgeFlow restored the 12.0-fix-base-not-insert-admin_user-if-already-exist branch July 5, 2019 15:29
@MiquelRForgeFlow MiquelRForgeFlow deleted the 12.0-fix-base-not-insert-admin_user-if-already-exist branch July 5, 2019 15:29
@MiquelRForgeFlow MiquelRForgeFlow restored the 12.0-fix-base-not-insert-admin_user-if-already-exist branch July 5, 2019 15:29
@MiquelRForgeFlow
Copy link
Contributor Author

MiquelRForgeFlow commented Jul 5, 2019

I happened to meet a database that already have an user_admin. Thus, I need this fix.

@pedrobaeza
Copy link
Member

@mreficent I don't think so. Maybe there was an error in the middle of your migration and thus end-migration scripts weren't executed.

@MiquelRForgeFlow
Copy link
Contributor Author

MiquelRForgeFlow commented Jul 5, 2019

No. I am sure. The xmlid base.user_admin existed in an old odoo version. I will find it.

@pedrobaeza
Copy link
Member

Unless you prove it pointing to the core code that makes this, for me it's 👎

@MiquelRForgeFlow
Copy link
Contributor Author

MiquelRForgeFlow commented Jul 5, 2019

Found 🤣 🎉. Around between v5 and v6, I think, not sure.
Creation commit of user_admin: odoo/odoo@3e1b346
Deletion commit of user_admin: odoo/odoo@5886791

Also, I will show you my proof:

Selection_065

So I will merge this PR!

@MiquelRForgeFlow MiquelRForgeFlow force-pushed the 12.0-fix-base-not-insert-admin_user-if-already-exist branch from b182933 to e982d08 Compare July 5, 2019 16:24
@pedrobaeza
Copy link
Member

pedrobaeza commented Jul 5, 2019

This is the result of not cleaning your DB with database_cleanup, not a normal process IMO. You should care about your data status that way. And you are not sure about where that record points to. And what about if other third party module adds that record and you are overwriting it for other purpose?

Let's hear @StefanRijnhart's opinion about this, but any way, if merged:

  • A comment must specify why we are using that.
  • res_id correctness must be assured: ON CONFLICT DO UPDATE... seems better.

@MiquelRForgeFlow MiquelRForgeFlow force-pushed the 12.0-fix-base-not-insert-admin_user-if-already-exist branch 4 times, most recently from c6dbb08 to 4acd1e7 Compare July 5, 2019 17:21
@MiquelRForgeFlow
Copy link
Contributor Author

I decided to use the "ON CONSTRAINT" mode to be more specific and avoid unexpected cases and be safer 😉

@pedrobaeza
Copy link
Member

My concern about overwriting an existing third party XML-ID still exists... Why don't you simply remove that XML-ID in your specific database.

@MiquelRForgeFlow MiquelRForgeFlow force-pushed the 12.0-fix-base-not-insert-admin_user-if-already-exist branch from 4acd1e7 to 30b1a7e Compare July 5, 2019 17:38
@MiquelRForgeFlow
Copy link
Contributor Author

Third party XML-ID will not be affected because they will have a different module, not the "base" module.

@pedrobaeza
Copy link
Member

You can declare that XML-ID from another module, but OK, I won't say more objections. Waiting @StefanRijnhart's approval.

@StefanRijnhart
Copy link
Member

Interestingly the tests say
2019-07-05 17:44:16,220 6685 ERROR openupgrade OpenUpgrade: base: error in migration script base/migrations/12.0.1.3/pre-migration.py: constraint "ir_model_data_module_name_uniq" for table "ir_model_data" does not exist. Any ideas?

@MiquelRForgeFlow
Copy link
Contributor Author

I searched a bit. This constraint existed in v8 but was removed in v9. In my force-push, I just put it because I was just having in front of me a database with that constraint and I thought it was a normal constraint. Shit.

@MiquelRForgeFlow MiquelRForgeFlow force-pushed the 12.0-fix-base-not-insert-admin_user-if-already-exist branch 2 times, most recently from c1c3337 to 8dfba00 Compare July 8, 2019 15:45
@MiquelRForgeFlow
Copy link
Contributor Author

Well, I proceeded finally with the most safely way possible hahaha

Please, update review

Copy link
Member

@StefanRijnhart StefanRijnhart left a comment

Choose a reason for hiding this comment

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

Alright!

@pedrobaeza
Copy link
Member

I still miss the explanation in a comment in the code of why doing all of this.

@MiquelRForgeFlow MiquelRForgeFlow force-pushed the 12.0-fix-base-not-insert-admin_user-if-already-exist branch from 8dfba00 to b00e1ce Compare July 9, 2019 09:20
@MiquelRForgeFlow
Copy link
Contributor Author

/ocabot merge

@OCA-git-bot
Copy link
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Rebased to 12.0-ocabot-merge-pr-1779-by-mreficent-bump-no, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit b00e1ce into OCA:12.0 Jul 9, 2019
OCA-git-bot added a commit that referenced this pull request Jul 9, 2019
Signed-off-by mreficent
@OCA-git-bot
Copy link
Contributor

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

PS: Don't worry if GitHub says there are unmerged commits: it is due to a rebase before merge. All commits of this PR have been merged into 12.0.

@MiquelRForgeFlow MiquelRForgeFlow deleted the 12.0-fix-base-not-insert-admin_user-if-already-exist branch July 9, 2019 09:55
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.

[11.0->12.0] Duplicate error when trying to create user_admin ir.model.data in pre-migration
4 participants