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

[ADD] invalid-commit: Add new check invalid-commit #28

Merged
merged 1 commit into from
May 18, 2016

Conversation

moylop260
Copy link
Collaborator

@moylop260 moylop260 commented May 17, 2016

@moylop260 moylop260 self-assigned this May 17, 2016
@moylop260 moylop260 force-pushed the master-oca-add-sql-commit-moy branch from 1d344fe to 1b71bca Compare May 17, 2016 02:57
@moylop260 moylop260 added this to the 1.3.0 milestone May 17, 2016
@moylop260 moylop260 force-pushed the master-oca-add-sql-commit-moy branch from 1b71bca to 4d4831c Compare May 17, 2016 03:13
@coveralls
Copy link

coveralls commented May 17, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling 4d4831c on vauxoo-dev:master-oca-add-sql-commit-moy into 6a8f696 on OCA:master.

@pedrobaeza
Copy link
Member

👍

1 similar comment
@luiseevaquer
Copy link

👍

@guewen
Copy link
Member

guewen commented May 17, 2016

Commit could still be valid such as in cron tasks or for performance reasons.
This is also noticed by the guidelines in:

All cr.commit() calls outside of the server framework from now on must have an explicit comment explaining why they are absolutely necessary, why they are indeed correct, and why they do not break the transactions. Otherwise they can and will be removed!

@moylop260
Copy link
Collaborator Author

moylop260 commented May 17, 2016

@guewen
You are right in some cases we need cr.commit
First step: Could you use cr.savepoint? No
Second step: Could you use a duplicated cursor to isolate the current transaction (More info here)? No

with openerp.api.Environment.manage():
    with openerp.registry(self.env.cr.dbname).cursor() as new_cr:
        # Create a new environment with new cursor database
        new_env = api.Environment(new_cr, self.env.uid, self.env.context)
        # with_env replace original env for this method
        self.with_env(new_env).write({'name': 'hello'})  # isolated transaction to commit
        new_env.cr.commit()  # Don't show a invalid-commit in this case
    # You don't need close your cr because is closed when finish "with"
# You don't need clear caches because is cleared when finish "with"

Third step: Then use cr.commit, but add an explicit comment explaining... in this comment you can add # pylint: disable=invalid-commit to bypass this check.

@guewen
Copy link
Member

guewen commented May 17, 2016

Third step: Then use cr.commit, but add an explicit comment explaining... in this comment you can add # pylint: disable=invalid-commit to bypass this check.

ok noted, thanks
👍

@oscarolar
Copy link

👍

@moylop260
Copy link
Collaborator Author

Somebody, could be merged it?

@pedrobaeza pedrobaeza merged commit d91b094 into OCA:master May 18, 2016
@luisg123v luisg123v deleted the master-oca-add-sql-commit-moy branch August 6, 2020 02:30
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.

None yet

6 participants