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

UnboundLocalError exception in nikola deploy #3479

Closed
hiway opened this issue Dec 2, 2020 · 3 comments
Closed

UnboundLocalError exception in nikola deploy #3479

hiway opened this issue Dec 2, 2020 · 3 comments
Labels

Comments

@hiway
Copy link
Contributor

hiway commented Dec 2, 2020

Environment

Python Version:

Python 3.7.9

Nikola Version:

Nikola v8.1.2 (installed from git master)

Operating System:

FreeBSD 12.2-RELEASE amd64

Description:

On running nikola deploy on a new site, after rsync completes, this exception is thrown:

  File "[...]/nikola/nikola/plugins/command/deploy.py", line 99, in _execute
    self._emit_deploy_event(last_deploy, new_deploy, clean, undeployed_posts)
UnboundLocalError: local variable 'clean' referenced before assignment

I looked at the source and noticed that clean is only set inside a condition:

def _execute(self, command, args):
"""Execute the deploy command."""
# Get last-deploy from persistent state
last_deploy = self.site.state.get('last_deploy')
if last_deploy is not None:
last_deploy = dateutil.parser.parse(last_deploy)
clean = False

To try and fix it, I changed the source to:

        if last_deploy is not None:
            last_deploy = dateutil.parser.parse(last_deploy)
            clean = False
        else:
            clean = True

That leads to another exception elsewhere:

  File "[...]/nikola/nikola/plugins/command/deploy.py", line 131, in _emit_deploy_event
    if last_deploy.tzinfo is None:
AttributeError: 'NoneType' object has no attribute 'tzinfo'

Which was fixed by changing the source code at:

new_deploy = datetime.utcnow()
self._emit_deploy_event(last_deploy, new_deploy, clean, undeployed_posts)

to:

        new_deploy = datetime.utcnow()
        if last_deploy is None:
            last_deploy = new_deploy
        self._emit_deploy_event(last_deploy, new_deploy, clean, undeployed_posts)

After this the deploy command has worked as I expected.

@hiway hiway added the bug label Dec 2, 2020
@hiway hiway mentioned this issue Dec 2, 2020
3 tasks
Kwpolska added a commit that referenced this issue Dec 5, 2020
@dvzrv
Copy link

dvzrv commented Jan 2, 2021

It would be awesome to see this fix in a bugfix release :)

@kayhayen
Copy link
Contributor

If I am not mistaken, there is no such bug fix release, does anyone happen to know which was the last release that didn't have this regression? I would downgrade to that.

@Kwpolska
Copy link
Member

I just released Nikola v8.1.3 with the fix for this.

devilgate pushed a commit to devilgate/nikola that referenced this issue Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants