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

Allow overriding signal for load data #1208

Closed
gythaogg opened this issue Sep 24, 2024 · 8 comments · Fixed by #1232 or #1209
Closed

Allow overriding signal for load data #1208

gythaogg opened this issue Sep 24, 2024 · 8 comments · Fixed by #1232 or #1209

Comments

@gythaogg
Copy link
Contributor

It should be possible to disable post save signals for extracting data into, for example date fields when importing data

Related to #984

@b1rger
Copy link
Contributor

b1rger commented Sep 24, 2024

There are two post_save signals in apis core:

def create_default_uri(sender, instance, created, raw, using, update_fields, **kwargs):

and

def add_to_session_collection(

The former can be disabled by setting the .skip_default_uri attribute on the instance that is being created to True or by setting the CREATE_DEFAULT_URI setting to False.
The latter only every does anything if used in a session that has collection ids in the session_collections variable.

I'd say thats what the issue requests?

@gythaogg
Copy link
Contributor Author

Sort of. LegacyDateMixin for example overrides the save method which I want to skip when I am importing data (or is this not a reasonable expectation?). I am not sure, honestly....

def save(self, *args, **kwargs):

@b1rger
Copy link
Contributor

b1rger commented Sep 25, 2024

Sort of. LegacyDateMixin for example overrides the save method which I want to skip when I am importing data (or is this not a reasonable expectation?). I am not sure, honestly....

Ah, oke, so its about the save() method, not a signal. Definitly a reasonoable expectation to be able to disable that behaviour. We can simply add a check in the LegacyDateMixin.save() method, similar to what we do in the create_default_uri signal

@gythaogg
Copy link
Contributor Author

gythaogg commented Sep 26, 2024

Thanks. For consistency is a settings variable preferrable? Just asking because originally I had something like this in mind

    def save(self, *args, **kwargs):
        if kwargs.get("bypass_parsing", False):
            super().save(*args, **kwargs)
            return self
        ...

@gythaogg
Copy link
Contributor Author

Or maybe it's better to have a single flag for loaddata in settings that does nothing beyond importing the data - no signals and no preprocessing in save methods?

@b1rger
Copy link
Contributor

b1rger commented Sep 26, 2024

Thanks. For consistency is a settings variable preferrable? Just asking because originally I had something like this in mind

    def save(self, *args, **kwargs):
        if kwargs.get("bypass_parsing", False):
            super().save(*args, **kwargs)
            return self
        ...

I would not put it in the kwargs, I would put it as an attribute in the instance. So you can create an instance of whatever and set a .please_dont_try_to_parse_my_dates attribute on that instance. If that is True the save() method should jump over the whole parsing block.

@b1rger
Copy link
Contributor

b1rger commented Sep 26, 2024

Or maybe it's better to have a single flag for loaddata in settings that does nothing beyond importing the data - no signals and no preprocessing in save methods?

I don't understand a flag for loaddata ... that does nothing beyond importing the data?

@gythaogg
Copy link
Contributor Author

I don't understand a flag for loaddata ... that does nothing beyond importing the data?

What I meant was a flag, say IMPORT_MODE in settings (instead of a DO_NOT_PARSE_WRITTEN_DATE flag for this save method alone), which is uniformly checked in any overridden save methods, post save signals to ensure that data is imported as such without fancy stuff like date_parsing or anything else

But if there is no need for such a behaviour except in this save method of DateMixin then this is a waste of time and I like your attribute solution better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants