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

Status 500 if edit call violates foreign key constraint #313

Open
AlexanderYAPPO opened this issue Aug 1, 2016 · 0 comments
Open

Status 500 if edit call violates foreign key constraint #313

AlexanderYAPPO opened this issue Aug 1, 2016 · 0 comments

Comments

@AlexanderYAPPO
Copy link
Contributor

If one tries to edit a language object and new values are not presented in the DB then status 500 will be returned.

It happens because we don't check if these new values already exist in the DB. If they're not here then we violate foreign key constraint and an exception is raised:

sqlalchemy.exc.IntegrityError: (psycopg2.IntegrityError) insert or update on table "dictionaryperspective" violates foreign key constraint "dictionaryperspective_parent_object_id_fkey"

We need to add try/catch blocks and return a proper answer.
Example of a problem code:

if language:
            if not language.marked_for_deletion:
                # TODO: Status 500 will be returned if arguments are invalid; add try/catch
                req = request.json_body
                if 'parent_client_id' in req:
                    language.parent_client_id = req['parent_client_id']
                if 'parent_object_id' in req:
                    language.parent_object_id = req['parent_object_id']
                if 'translation_gist_client_id' in req:
                    language.translation_gist_client_id = req['translation_gist_client_id']
                if 'translation_gist_object_id' in req:
                    language.translation_gist_object_id = req['translation_gist_object_id']
                request.response.status = HTTPOk.code
                return response
myrix pushed a commit to myrix/lingvodoc that referenced this issue Sep 21, 2020
myrix added a commit that referenced this issue Sep 21, 2020
Bulk cognate disconnects from Xlsx #313
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant