There is a lot of repetition between sqlalchemy models and marshmallow schema
Use https://marshmallow-sqlalchemy.readthedocs.io to remove this duplication
This is a parent issue and new contributors can take an API component and send contributions converting their schemas
Hi, I would like to work on this issue. This will be my first pull request here. Can you help me with where to start?
Take a look at codebase and marshmallow schema files. Read about the above mentioned library and tell which component will you start working on here
@iamareebjamal I am willing towork on any of the schemas but I am not able to figure out the repetitions. I see that models serialize the data. Can you give an example?
Can you please take a look at the library I have linked in the issue and read about its usage. The issue will become apparent
@iamareebjamal I went through the library. I need to rewrite the models and schemas using marshmallow-sqlalchemy but I am unable to find the repetiton. As per the documentation we still need to deserialize after the schema class. Sorry I am new but could you show me an example?
You don't need to rewrite the models. Just the schema
Can you see the repetition now?
I would like to work on this issue @iamareebjamal @prateekj117
Go ahead
On Tue, 15 Oct, 2019, 11:08 Anirban Banik, notifications@github.com wrote:
I would like to work on this issue @iamareebjamal
https://github.com/iamareebjamal @prateekj117
https://github.com/prateekj117—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/fossasia/open-event-server/issues/6467?email_source=notifications&email_token=AKQMTLSA6SBYGQHVE2GKXHDQOVJOBA5CNFSM4I2RGXO2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBHPKLA#issuecomment-542045484,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AKQMTLX3RTUDMK3B5SGIPF3QOVJOBANCNFSM4I2RGXOQ
.
@kushthedude @iamareebjamal @prateekj117 I am working on the event schemas.
@iamareebjamal @prateekj117 taking this up
@iamareebjamal Hey! I'd like to take this issue.
So basically i just have to remove the entire marshmallow schema(repeated) and put the sqlalchemy model there
eg -> model = Event
under Meta class in EventSchemaPublic.
And similarly for other API components.
Right?
If it works, yes
Can I explore a bit and work on this, if there's still more to do?
@iamareebjamal :
Hi,
If this issue is till open, can I work on this ?
Yes
@iamareebjamal :
As per the latest update on: https://marshmallow-sqlalchemy.readthedocs.io/en/latest/
For the model Book relationship with model Author, there are changes required in the Schema of Author and Book as well.
Models:
class Author(Base):
__tablename__ = "authors"
id = sa.Column(sa.Integer, primary_key=True)
name = sa.Column(sa.String, nullable=False)
def __repr__(self):
return "<Author(name={self.name!r})>".format(self=self)
class Book(Base):
__tablename__ = "books"
id = sa.Column(sa.Integer, primary_key=True)
title = sa.Column(sa.String)
author_id = sa.Column(sa.Integer, sa.ForeignKey("authors.id"))
author = relationship("Author", backref=backref("books"))
Schema:
class AuthorSchema(SQLAlchemyAutoSchema):
class Meta:
model = Author
include_relationships = True #
load_instance = True
class BookSchema(SQLAlchemyAutoSchema):
class Meta:
model = Book
include_fk = True #
load_instance = True
Hey would like to contribute to this
Hey, I want to work on this. Can I contribute?
Most helpful comment
@kushthedude @iamareebjamal @prateekj117 I am working on the event schemas.