cs91chris / flask_autocrud Goto Github PK
View Code? Open in Web Editor NEWAutomatically generate a RESTful API service for CRUD operation on database and advanced search
License: MIT License
Automatically generate a RESTful API service for CRUD operation on database and advanced search
License: MIT License
py37\lib\site-packages\jinja2\environment.py", line 907, in select_template
message=u"Tried to select from an empty list " u"of templates."
works on validation
(.venv) C:\Users\xxxxxx\Documents\gits\fid-forward>curl -i http://127.0.0.1:5000/api/v1/validation/meta
HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 763
Server: Werkzeug/1.0.1 Python/3.7.0
Date: Mon, 25 May 2020 12:32:57 GMT
{"description": null, "fields": [{"description": null, "key": true, "name": "id", "nullable": false, "type": "int", "unique": null}, {"description": null, "key": false, "name": "validation_date",
"nullable": true, "type": "datetime", "unique": null}, {"description": null, "key": false, "name": "comment", "nullable": true, "type": "str", "unique": null}, {"description": null, "key": false,
"name": "status", "nullable": true, "type": "str", "unique": null}, {"description": null, "key": false, "name": "id_user", "nullable": true, "type": "int", "unique": null}], "methods": ["HEAD", "F
ETCH", "DELETE", "PATCH", "POST", "GET", "PUT", "OPTIONS"], "name": "validation", "related": {"demand": "/api/v1/demand", "user": "/api/v1/user"}, "url": "/api/v1/validation"}
not works on application
(.venv) C:\Users\xxxxx\Documents\gits\fid-forward>curl -i http://127.0.0.1:5000/api/v1/application/meta
HTTP/1.0 500 INTERNAL SERVER ERROR
Content-Type: application/problem+json
Content-Length: 1092
Server: Werkzeug/1.0.1 Python/3.7.0
Date: Mon, 25 May 2020 12:33:12 GMT
{"detail": "Traceback (most recent call last):\n File \"C:\\Users\\PCDxxxx1\\programme\\py37\\lib\\site-packages\\flask\\app.py\", line 1950, in full_dispatch_request\n rv = self.dispatch_req
uest()\n File \"C:\\Users\\Pxxx1\\programme\\py37\\lib\\site-packages\\flask\\app.py\", line 1936, in dispatch_request\n return self.view_functions[rule.endpoint](**req.view_args)\n File
\"C:\\Users\\PCDTxxx1\\programme\\py37\\lib\\site-packages\\flask\\views.py\", line 89, in view\n return self.dispatch_request(*args, **kwargs)\n File \"C:\\Users\\PCDxxx81\\programme\\py37\
\lib\\site-packages\\flask_autocrud\\service.py\", line 45, in dispatch_request\n return controller(*args, **kwargs)\n File \"C:\\Users\\Pxxxx1\\programme\\py37\\lib\\site-packages\\flask_a
utocrud\\service.py\", line 161, in get\n return self._response.build_response(builder, model.description())\nTypeError: 'InstrumentedAttribute' object is not callable\n", "instance": "about:bl
ank", "response": null, "status": 500, "title": "Internal Server Error", "type": "https://httpstatuses.com/500"}
Hi,
first of all, thanks for the project!
Is it possible to include related fields in GET requests as well?
I want to use Apollo GraphQL on top but can't implement your custom FETCH method there.
My model is a company that has multiple arrays of id's (users, addresses, invoices, etc). These id's are on other microservices. With FETCH I can easily query them as related ressources.
Or am I missing another way here?
Best regards
models.py
class Company(BaseModel):
__tablename__ = 'company'
id = Column(Integer, primary_key=True)
name = Column(String(150), nullable=False, unique=True)
addresses = relationship("Address", foreign_keys="Address.company_id", back_populates='company')
class Address(BaseModel):
__tablename__ = 'addresses'
id = Column(Integer, primary_key=True)
address_id = Column(Integer)
company_id = Column(Integer, ForeignKey('company.id'))
company = relationship("Company", foreign_keys=company_id)
curl --request FETCH call
{ "fields": [ "name" ], "related": { "addresses": [ "address_id" ] } }
examples
with example databaseautocrud -c examples/configuration.yaml
python examples/run.py
NOTE has a warning, [2024-02-08 19:37:19,141] WARNING in handler: invalid handler: 'None'
Hi @cs91chris,
First of all, thank you for this awesome project!
I am getting the above error, when I try to run a request against any of the model endpoints,
import os
import pyodbc
from dotenv import load_dotenv
from flask import Flask
from flask_autocrud import AutoCrud, Model
from flask_sqlalchemy import SQLAlchemy
load_dotenv()
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = f"{os.environ.get('DB_CONN_STR')}?driver={pyodbc.drivers()[-1]}"
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['AUTOCRUD_METADATA_ENABLED'] = True
app.config['AUTOCRUD_DATABASE_SCHEMA'] = os.environ.get('DB_TABLE_SCHEMA')
db = SQLAlchemy(app)
with app.app_context():
AutoCrud(app, db)
if __name__ == '__main__':
app.run(debug=True)
When I run a requests against the /resources
endpoint I see all of the tables in my schema though.
Am I doing something wrong here?
Note: My SQLAlchemy
version is 2.0.6.
Extract:
127.0.0.1 - - [08/Feb/2024 18:38:56] "?[33mGET / HTTP/1.1?[0m" 404 -
127.0.0.1 - - [08/Feb/2024 18:38:56] "?[33mGET /favicon.ico HTTP/1.1?[0m" 404 -
127.0.0.1 - - [08/Feb/2024 18:39:02] "?[33mGET /admin HTTP/1.1?[0m" 404 -
127.0.0.1 - - [08/Feb/2024 18:39:11] "?[33mGET /resources HTTP/1.1?[0m" 404 -
setup.py requirements are too greedy and pull in version that are incompatible with current code:
AttributeError: module 'flask.json' has no attribute 'JSONEncoder'
ImportError: cannot import name 'url_quote' from 'werkzeug.urls'
ImportError: cannot import name 'escape' from 'jinja2'
ImportError: cannot import name 'json' from 'itsdangerous'
AttributeError: module 'sqlalchemy' has no attribute '__all__'. Did you mean: '__file__'?
SQLalchemy error is likely another manifestation of #6 (i.e. incompatible with SQLalchemy version 2.x).
Considering the following DB schema
CREATE TABLE IF NOT EXISTS "Genres" (
"genreId" TEXT,
"genreName" TEXT,
"genreDesc" TEXT,
PRIMARY KEY("genreId")
);
CREATE TABLE IF NOT EXISTS "Artists" (
"artistId" TEXT,
"artistName" TEXT,
"artistPhoto" TEXT,
"genreRef" TEXT,
PRIMARY KEY("artistId"),
FOREIGN KEY("genreRef") REFERENCES "Genres"("genreId")
);
CREATE TABLE IF NOT EXISTS "SimilarTo" (
"artist1Ref" TEXT,
"artist2Ref" TEXT,
PRIMARY KEY("artist1Ref","artist2Ref"),
FOREIGN KEY("artist1Ref") REFERENCES "Artists"("artistId"),
FOREIGN KEY("artist2Ref") REFERENCES "Artists"("artistId")
);
CREATE TABLE IF NOT EXISTS "Labels" (
"labelId" TEXT,
"labelName" TEXT,
PRIMARY KEY("labelId")
);
CREATE TABLE IF NOT EXISTS "Songs" (
"songId" TEXT,
"songTitle" TEXT,
"songLength" NUMERIC,
PRIMARY KEY("songId")
);
CREATE TABLE IF NOT EXISTS "AppearsOn" (
"albumRef" TEXT,
"songRef" TEXT,
PRIMARY KEY("albumRef","songRef"),
FOREIGN KEY("albumRef") REFERENCES "Albums"("albumId"),
FOREIGN KEY("songRef") REFERENCES "Songs"("songId")
);
CREATE TABLE IF NOT EXISTS "ParticipateTo" (
"artistRef" TEXT,
"albumRef" TEXT,
FOREIGN KEY("artistRef") REFERENCES "Artists"("artistId"),
FOREIGN KEY("albumRef") REFERENCES "Albums"("albumId")
);
CREATE TABLE IF NOT EXISTS "Albums" (
"albumId" TEXT,
"albumYear" INTEGER,
"albumTitle" TEXT,
"albumImage" TEXT,
"labelRef" TEXT,
"genreRef" TEXT,
PRIMARY KEY("albumId"),
FOREIGN KEY("labelRef") REFERENCES "Labels"("labelId"),
FOREIGN KEY("genreRef") REFERENCES "Genres"("genreId")
);
Trying to access /artists/id_of_artist/albums raises a 500 error. The exact error is sqlalchemy filter complaining about
Artistsnot belonging to its
modelparameter. The problem seems to come from
qs2sqla.pybut it is hard to find exactly why without taking time to understand
flask_autocrud` inner working :-(.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.