migra icon indicating copy to clipboard operation
migra copied to clipboard

return 2, but why ?

Open panchan173 opened this issue 3 years ago • 4 comments

Hello, When I run migra with the option "--with-privileges" (there are also the options --unsafe --schema public, but not relevant), the tool returns error code 2 without error messages. The sql file is however well created and functional. How can I get more informations about the reason (debug or other)?

panchan173 avatar Dec 14 '20 10:12 panchan173

Cheers for the question. There's no error as such, the error codes are designed to match unix's diff command, which returns zero if there are no differences but no-zero if there are.

This isn't super obvious, and should probably be better documented somewhere.

djrobstep avatar Dec 14 '20 10:12 djrobstep

Great explanation.

As an aside, it might be nice to have a --ci parameter or something that returns 0 unless there is an error; most CI systems will choke on a status code of 2 (which is why I'm here) :)

dancrumb avatar Jan 11 '21 00:01 dancrumb

This is very much the same as Django ticket #25604 (Add --check flag to makemigrations; return 0 exit status for no new migrations) and my suggestion is to follow their proposal:

Proposal: add --check flag to the makemigrations management command. This flag will return 0 if no new migrations will be created. It will return non-zero if models contain changes without migrations. This will deprecrate the --exit flag originally discussed here: ​https://groups.google.com/forum/#!topic/django-developers/I3M6B-wYYd8/discussion. The problem with --exit is that it return the opposite exit status from what continuous integration servers typically expect.

In the context of migra, the --check argument should cause error codes matching the diff command to be returned, otherwise the normal behaviour should be zero if everything worked OK, or non-zero if there were errors.

tysonclugg avatar Sep 01 '21 06:09 tysonclugg

To add a vote for this: I'd like to use this tool from a Makefile, but the nonzero exit causes make to abort.

tomwhipple avatar Dec 01 '22 23:12 tomwhipple