[Tutor] Error with sqlalchemy

Mats Wichmann mats at wichmann.us
Tue Aug 1 09:38:56 EDT 2017


On 08/01/2017 05:13 AM, rakesh sharma wrote:
> Hi All
> 
> 
> I am getting an error in python. Its a flask app that I am doing
> 
> I am getting the error
> 
> TypeError: utf_8_decode() argument 1 must be string or buffer, not long
> 
> at this point in the code
> 
> ship_schedules = ShipSchedule.query.all()
> 
> The schema definition is like that I gave below, there is no mismatch between the schema and the table definition in the mysql DB.
> 
> class ShipSchedule(Base):
> 
>     __tablename__ = 'ship_schedule'
> 
>     vessel_imo_no = Column(Integer, primary_key=True, nullable=False)
>     commodity_product_code = Column(String, nullable=False)
>     port_port_code = Column(String, nullable=False)
>     cargo_quantity = Column(String, nullable=False)
>     activity = Column(String, nullable=False)
>     date_from = Column(Date, nullable=False)
>     date_to = Column(Date, nullable=False)
> 
> 
> """
>     Ship schedule schema
> """
> 
> 
> class ShipScheduleSchema(Schema):
>     vessel_imo_no = fields.Int(dump_only=True)
>     commodity_product_code = fields.Str()
>     port_port_code = fields.Str()
>     cargo_quantity = fields.Int()
>     activity = fields.Str()
>     date_from = fields.Date()
>     date_to = fields.Date()
> 
> the mysql table defintion is as follows
> 
> 
> [cid:e101f2ac-60ca-426a-8e53-01afd9e9414d]

this is not viewable, at least not here.

you've potentially got an issue in your cargo quantity definition in the
two classes, possibly take a closer look at that (String vs fields.Int()).

this is a pretty specialized sort of query, probably the sqlalchemy
community would be more expert in this stuff (given you said you've
exhausted stackoverflow already). maybe they have knowledge of some
consistency-checking tool that could detect mismatches?


More information about the Tutor mailing list