Skip to content

[BUG] Several NAV scripts run twice on every invocation #2877

@lunkwill42

Description

@lunkwill42

Describe the bug

Due to the changed method of script installation in NAV 5.9, the navsyncdb, navpgdump and navtopology commands now run twice on every invocation. This isn't normally a big problem, but it can result in strange output and errors during an invocation, for example if using the command to create the initial NAV database (as the second run will typically fail because the database was already created and populated by the first run).

The principal problem is because nav/bin/navsyncdb.py and the other mentioned scripts are implemented to import main() from somewhere else, but do not implement a if __name__ == '__main__' guard to avoid running main() as a side effect of an import operation, like so:

from nav.pgsync import main
main()

To Reproduce

Steps to reproduce the behavior (WARNING: This is a destructive command, never run it in a production environment):

  1. Run navsyncdb from the command line.
  2. See double output:
$ navsyncdb
No outstanding schema changes.
No outstanding schema changes.

Expected behavior

navsyncdb, navpgdump and navtopology should only run once per invocation.

Environment (please complete the following information):

  • NAV version installed: 5.9.1

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions