These are chat archives for fossasia/open-event-server

5th
Jul 2018
Saurav Tiwary
@srv-twry
Jul 05 2018 02:40

Since the before_post method is not really called "before" but in between the actual post function in flask-rest-jsonapi

It is called before the object is created in the database which works fine for our case.

To fix this, should I create a new method decide_schema()of ResourceList that does this part?

I am strongly in disagreement with this. The server should be self sufficient and shouldn't rely on the library to do things. For the rest of the models it is not needed and hence I don't see any reason why we need it here.

Before the object is created in the database, the before_post method is called, you can edit the data passed to it and then the object will be created according to the edited data.
Saurabh Chaturvedi
@schedutron
Jul 05 2018 06:44

Before the object is created in the database, the before_post method is called, you can edit the data passed to it and then the object will be created according to the edited data.

How is it different from before_create_object()?

Saurav Tiwary
@srv-twry
Jul 05 2018 06:45
Not sure.
You can use before_create_object then.
The point is that the server should be self sufficient.
Saurabh Chaturvedi
@schedutron
Jul 05 2018 06:46

For the rest of the models it is not needed and hence I don't see any reason why we need it here.

Discount codes are little different, their schema is decided based on the data the server receives.

def before_post(self, args, kwargs, data):
        if data['used_for'] == 'ticket':
            self.schema = DiscountCodeSchemaTicket
But unfortunately, this doesn't change the schema :(
Saurav Tiwary
@srv-twry
Jul 05 2018 06:48
We are doing similar things in the Event also. When the user is the admin or event organizer we send more details otherwise to the public we only send details which aren't sensitive.
Saurabh Chaturvedi
@schedutron
Jul 05 2018 06:48
I'm looking for an alternative that doesn't require change in the library.
Saurav Tiwary
@srv-twry
Jul 05 2018 06:48
Similarly in many places.

I'm looking for an alternatives that doesn't require change in the library.

First fix the relationship that you've defined. It's wrong.

Saurabh Chaturvedi
@schedutron
Jul 05 2018 06:48

We are doing similar things in the Event also. When the user is the admin or event organizer we send more details otherwise to the public we only send details which aren't sensitive.

That's a GET.

Saurav Tiwary
@srv-twry
Jul 05 2018 06:49
So why can't we do it for POST ??
def before_post(self, args, kwargs, data):
        if data['used_for'] == 'ticket':
            self.schema = DiscountCodeSchemaTicket

But unfortunately, this doesn't change the schema :(

Alright, I'll have a look. Please fix the relationship first.

Ping me when you're done with the relationship thing.
Saurabh Chaturvedi
@schedutron
Jul 05 2018 06:52

So why can't we do it for POST ??

Because before_post() isn't really called "before" the POST code, but before_get() is called correctly before GET.

Alright, I'll have a look. Please fix the relationship first.

:+1: Working on it.

Saurav Tiwary
@srv-twry
Jul 05 2018 06:52
okay, I'll look into it after you're done with the correct relationship :+1:
Saurav Tiwary
@srv-twry
Jul 05 2018 14:44
@schedutron I pulled the code and looked at it. It seems that you're right in saying that the before_post is called after the schema is decided, so we can't use before_post method to decide the schema.
So two alternatives:
  1. Shorter but non-recommended one: Modify the library for it.
  2. Time consuming but the correct solution: Split the Discount code into two separate endpoints. a. DiscountCodeEvent b. DiscountCodeTicket.
I had created an issue for it about 15 days ago: fossasia/open-event-server#4937
I am really not sure what to do for this. If we choose to split them, then it would take a really long time. We also have to modify the client applications i.e. the FE and android apps as well.
Saurav Tiwary
@srv-twry
Jul 05 2018 14:51
Another alternative that I can think of is to add the tickets relationship to both the schemas for the time being. For the Discount codes meant for events, they will be null but won't cause any issues. Probably this is the way to go right now.
Does anyone else have a feasible alternative in mind ? @bhaveshAn @maxlorenz @Kreijstal @mayank8318
Saurabh Chaturvedi
@schedutron
Jul 05 2018 16:12
@srv-twry The third option means adding the tickets relationship to DiscountCodeSchemaPublic, from which the two schemas inherit.
Then we will have to shift the marketer relationship as well, because it faces the same problem.
If that is the way to go, there will be a lot of relationships displayed - in total 4 for every ticket - event, events, marketer and tickets.
Saurav Tiwary
@srv-twry
Jul 05 2018 22:39
I do know that. They will be null. Any other alternatives. I am not up for doing things in the library.