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

Implement m2m_to_o2m #343

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Conversation

carmenbianca
Copy link
Member

Ported over from OCA/OpenUpgrade#3911 in the hope that it can be more broadly useful.

Tagging @remytms

Co-authored-by: Rémy Taymans <[email protected]>
Signed-off-by: Carmen Bianca BAKKER <[email protected]>
@carmenbianca carmenbianca marked this pull request as ready for review August 28, 2023 15:15
Signed-off-by: Carmen Bianca BAKKER <[email protected]>
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.

Not sure about the use case, but this will probably needs a migration from one record with m2m to several records with m2o.

openupgradelib/openupgrade.py Outdated Show resolved Hide resolved
Signed-off-by: Carmen Bianca BAKKER <[email protected]>
Signed-off-by: Carmen Bianca BAKKER <[email protected]>
@carmenbianca
Copy link
Member Author

I pushed some additional work. Specifically:

  • Better documentation.
  • Better logging (it now says which records were linked, and which will remain linked).
  • The UPDATE became deterministic (only one2many with lowest id retained; naïve strategy, but m2m-to-m2o is impossible anyway, so the condition is always going to be arbitrary).

I want to see if I can create a strategy that will copy records to prevent data loss.

@carmenbianca carmenbianca marked this pull request as draft August 29, 2023 09:32
Signed-off-by: Carmen Bianca BAKKER <[email protected]>
Signed-off-by: Carmen Bianca BAKKER <[email protected]>
@carmenbianca
Copy link
Member Author

Ready for review again. Changes since last update:

  • Better documentation/naming. I decided to call the entities in the One2many relationship parent/child instead of source/comodel, which was not clear.
  • Even more logging.
  • Added a 'COPY' strategy that, instead of causing data loss, copies the child record for each parent record that wants one.

The copy strategy uses the Odoo ORM (copy()). I don't know if this is good/kosher/permissible. Doing this manually in SQL seemed like a Really Bad Idea™ to me.

@carmenbianca carmenbianca marked this pull request as ready for review August 29, 2023 13:29
@carmenbianca
Copy link
Member Author

carmenbianca commented Aug 29, 2023

Oof, syntax error because Travis uses Python 3.6.

edit: ImportError because Travis uses Python 3.6 :'(

Signed-off-by: Carmen Bianca BAKKER <[email protected]>
Signed-off-by: Carmen Bianca BAKKER <[email protected]>
@legalsylvain
Copy link
Contributor

Oof, syntax error because Travis uses Python 3.6.
edit: ImportError because Travis uses Python 3.6 :'(

We have to switch to github actions, but not done until now (#322)...

Signed-off-by: Carmen Bianca BAKKER <[email protected]>
@carmenbianca
Copy link
Member Author

carmenbianca commented Aug 31, 2023

Turns out Python 2 was the problem, not Python 3.6. I added a backport dependency, but it wouldn't be very difficult to get rid of the Enum and use something more primitive.

edit: the backport is incomplete, ugh. I'll fix this someday soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants