django-prometheus icon indicating copy to clipboard operation
django-prometheus copied to clipboard

Migrations created cause "syntax error"

Open george-miller opened this issue 4 years ago • 11 comments

Hello,

Here is the versions I'm using

Django             3.0.3     
django-prometheus  2.0.0     

I have models like

class Foo(ExportModelOperationsMixin('foo'), models.Model):
     ...

However, whenever I run makemigrations this line is added to the migration, which is invalid python syntax.

bases=(django_prometheus.models.ExportModelOperationsMixin.<locals>.Mixin, models.Model)

Not sure if this is a django problem or a django_prometheus problem but sadly I can't use this package because of this. Any help would be greatly appreciated!

george-miller avatar Apr 01 '20 18:04 george-miller

you can always manually edit the migrations scripts Django generates... I have seen cases where django doesn't properly resolve stuff... you can also try: https://github.com/korfuri/django-prometheus/issues/34#issuecomment-340775515

asherf avatar Apr 01 '20 19:04 asherf

I encountered the same problem, can someone help me?

YuXiaoCoder avatar May 21 '20 08:05 YuXiaoCoder

@YuXiaoCoder have you tried the workaround I mentioned in a previous comment ? https://github.com/korfuri/django-prometheus/issues/217#issuecomment-607435156

asherf avatar May 21 '20 15:05 asherf

I encountered the same problem today. The workaround mentioned does not do anything to the generated migrations.

SchoolGuy avatar Jul 19 '20 15:07 SchoolGuy

Repository with the code where I could reproduce the problem: https://gitlab.com/pfpa/pfpa

SchoolGuy avatar Jul 19 '20 15:07 SchoolGuy

I guess this is a duplicate of https://github.com/korfuri/django-prometheus/issues/42

SchoolGuy avatar Jul 19 '20 15:07 SchoolGuy

@YuXiaoCoder have you tried the workaround I mentioned in a previous comment ? #217 (comment)

It is possible to edit the migration file manually

YuXiaoCoder avatar Jul 19 '20 16:07 YuXiaoCoder

@YuXiaoCoder have you tried the workaround I mentioned in a previous comment ? #217 (comment)

It is possible to edit the migration file manually

Yes of course. I used the last comment in the suggested issue.

SchoolGuy avatar Jul 19 '20 19:07 SchoolGuy

Could somebody please create a PR for it ?

dmpe avatar Aug 16 '20 10:08 dmpe

I've got the same problem and I found a work-around. I created my model without the ExportModelOperationsMixin annotation, ran the makemigration and migrate commands and then added the ExportModelOperationsMixin annotation.

It works :)

fgiudici95 avatar Jun 24 '21 15:06 fgiudici95

Any code solution for this. I cannot manually change the migration files when running tests. my test runs makemigrations to recreate the migrations and then migrate. It is able to make the migrations without error with this line PROMETHEUS_EXPORT_MIGRATIONS = False but it throws a syntax error when migrate command is run because of the syntax

File "/app/apps/form/migrations/0001_initial.py", line 131
bases=(django_prometheus.models.ExportModelOperationsMixin.<locals>.Mixin, models.Model),
                                                                                                                 ^
        | SyntaxError: invalid syntax

Anyone able to get past it without the manual changes??

boscoseries avatar Aug 29 '22 09:08 boscoseries