Opened 6 years ago

Closed 6 years ago

#29672 closed Bug (invalid)

Returns an empty model field that is filled with a trigger in the database.

Reported by: Vaskevich Aleksander Owned by: nobody
Component: Uncategorized Version: 2.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Vaskevich Aleksander)

my model

blank_and_null = {'blank': True, 'null': True}

class Message(....):
    ....
    chat_local_id = models.BigIntegerField(
        verbose_name='local id message for chat',
        **blank_and_null)
    ....

I transferred some logic to the trigger database.
Here is my trigger

CREATE OR REPLACE FUNCTION public.inc_chat_local_id()
     RETURNS trigger
     LANGUAGE 'plpgsql' AS
$BODY$
DECLARE
	new_count_message INTEGER;
BEGIN
   	UPDATE v1_chat_chat SET count_message = count_message + 1
 		WHERE id = NEW.chat_id;

	SELECT v1_chat_chat.count_message INTO new_count_message FROM v1_chat_chat
		WHERE id = NEW.chat_id;

	NEW.chat_local_id = new_count_message;

 	RETURN NEW;
END;
$BODY$;

DROP TRIGGER IF EXISTS generate_chat_local_id on v1_chat_message;

CREATE TRIGGER generate_chat_local_id
  BEFORE INSERT
  ON v1_chat_message
  FOR EACH ROW
  EXECUTE PROCEDURE inc_chat_local_id();

It works as I expect
before insertion requests, it sets the value of chat_local_id
when I execute the insert query through django
chat_local_id empty field
when I re-query this entry, the chat_local_id is set to

my Python version: 3.6
my database: Postgres

Change History (2)

comment:1 by Vaskevich Aleksander, 6 years ago

Description: modified (diff)
Type: UncategorizedBug

comment:2 by Carlton Gibson, 6 years ago

Resolution: invalid
Status: newclosed

I'm sorry but there's nothing actionable as a bug report for Django here. It looks more like a usage question as-is.

At the very least you need to narrow this down to something specific that you can show Django is doing wrong.
(There are any number of things that could be happening here.)

I suggest you investigate further and then try other support channels for help. (The django users mailing list, StackOverflow, etc.)

If you can identify an specific issue with Django itself then we would be happy to review.

Note: See TracTickets for help on using tickets.
Back to Top