Re: Logging to Database while using @transaction.commit_manually decorator

2009-06-09 Thread Chris Stoyles
The only log entries I want committed are the ones that tell me why a
roll-back occurred. What you've said below sounds like a good enough
solution, thanks for all your input.

Cheers,
Chris

On Mon, Jun 8, 2009 at 11:38 PM, Karen Tracey  wrote:

> On Mon, Jun 8, 2009 at 5:39 AM, Chris Stoyles  wrote:
>
>> Hi Thomas,
>>
>> The reason I want to be able to rollback (but still commit by log entries)
>> is because it is sometimes valid for this particular view to throw an
>> exception and fail. If this happens, I need to rollback any model objects
>> that have been created and saved up to the point at which the view fails
>> (again, except for any logging that has been done). The view contains a big
>> try/except statement and the rollback is in the "except" part.
>>
>> I may have to approach this a different way, because it doesn't look like
>> I can easily do a fine-grained commit.
>>
>
> Sounds like the easiest thing to do would be to accumulate (but not call
> save() on) LogEntry objects as you do the work, then at the end either after
> you have either rolled back the main work or are about to commit it, save()
> whatever LogEntry objects you have accumulated.  (I'd probably also want to
> indicate in the entries associated with work that was ultimately rolled back
> that that happened, otherwise it seems the log might be a bit confusing,
> containing entries for stuff that ultimately got rolled back...but maybe
> that's not an issue for the log you are keeping?)
>
> Karen
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Logging to Database while using @transaction.commit_manually decorator

2009-06-08 Thread Karen Tracey
On Mon, Jun 8, 2009 at 5:39 AM, Chris Stoyles  wrote:

> Hi Thomas,
>
> The reason I want to be able to rollback (but still commit by log entries)
> is because it is sometimes valid for this particular view to throw an
> exception and fail. If this happens, I need to rollback any model objects
> that have been created and saved up to the point at which the view fails
> (again, except for any logging that has been done). The view contains a big
> try/except statement and the rollback is in the "except" part.
>
> I may have to approach this a different way, because it doesn't look like I
> can easily do a fine-grained commit.
>

Sounds like the easiest thing to do would be to accumulate (but not call
save() on) LogEntry objects as you do the work, then at the end either after
you have either rolled back the main work or are about to commit it, save()
whatever LogEntry objects you have accumulated.  (I'd probably also want to
indicate in the entries associated with work that was ultimately rolled back
that that happened, otherwise it seems the log might be a bit confusing,
containing entries for stuff that ultimately got rolled back...but maybe
that's not an issue for the log you are keeping?)

Karen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Logging to Database while using @transaction.commit_manually decorator

2009-06-08 Thread Thomas Guettler



Chris Stoyles schrieb:
> Hi Thomas,
> 
> The reason I want to be able to rollback (but still commit by log entries)
> is because it is sometimes valid for this particular view to throw an
> exception and fail. If this happens, I need to rollback any model objects
> that have been created and saved up to the point at which the view fails
> (again, except for any logging that has been done). The view contains a big
> try/except statement and the rollback is in the "except" part.

You can't do this with SQL transaction. If you rollback, logging rows created 
with the
same database connetion will roll back, too.


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Logging to Database while using @transaction.commit_manually decorator

2009-06-08 Thread Chris Stoyles
Hi Thomas,

The reason I want to be able to rollback (but still commit by log entries)
is because it is sometimes valid for this particular view to throw an
exception and fail. If this happens, I need to rollback any model objects
that have been created and saved up to the point at which the view fails
(again, except for any logging that has been done). The view contains a big
try/except statement and the rollback is in the "except" part.

I may have to approach this a different way, because it doesn't look like I
can easily do a fine-grained commit.

Cheers,
Chris

On Mon, Jun 8, 2009 at 3:14 PM, Thomas Guettler  wrote:

>
> Hi Chris,
>
> please explain in more depth what you want to do. If you
> do rollback, all changes won't be written to the database. Even
> all savepoints won't be stored.
>
> Why do you want to rollback? If you want your changes
> to get saved, you need to call transaction.commit() at the end.
>
> ChrisStoyles schrieb:
> > Hi All,
> >
> > I just wanted to quickly reach out to the group for ideas as to why I
> > cannot get this to work:
> >
> > @transaction.commit_manually
> > def some_view(request):
> > # some view logic goes here
> >
> > sid = transaction.savepoint()
> > le = models.LogEntry()
> > le.message = 'A test log message'
> > le.save()
> > transaction.savepoint_commit(sid)
> >
> > transaction.rollback()
> >
> > My database back end is Postgres 8.3 and the engine I am using is
> > postgresql_psycopg2. Any ideas as to why my LogEntry would not be
> > committed to the database? I am not getting any exceptions being
> > raised, the code executes as though it has all worked perfectly.
>
>
> --
> Thomas Guettler, http://www.thomas-guettler.de/
> E-Mail : guettli (*)
> thomas-guettler + de
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Logging to Database while using @transaction.commit_manually decorator

2009-06-08 Thread Thomas Guettler

Hi Chris,

please explain in more depth what you want to do. If you
do rollback, all changes won't be written to the database. Even
all savepoints won't be stored.

Why do you want to rollback? If you want your changes
to get saved, you need to call transaction.commit() at the end.

ChrisStoyles schrieb:
> Hi All,
> 
> I just wanted to quickly reach out to the group for ideas as to why I
> cannot get this to work:
> 
> @transaction.commit_manually
> def some_view(request):
> # some view logic goes here
> 
> sid = transaction.savepoint()
> le = models.LogEntry()
> le.message = 'A test log message'
> le.save()
> transaction.savepoint_commit(sid)
> 
> transaction.rollback()
> 
> My database back end is Postgres 8.3 and the engine I am using is
> postgresql_psycopg2. Any ideas as to why my LogEntry would not be
> committed to the database? I am not getting any exceptions being
> raised, the code executes as though it has all worked perfectly.


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Logging to Database while using @transaction.commit_manually decorator

2009-06-07 Thread Chris Stoyles
Hi Karen,

Yes it does look as though I am using them backwards. I am at a bit of a
loss as to how to get around this problem, though it is Monday morning and
my brain isn't fully into gear yet. Can anyone think of a way for me to
bypass the transaction management? I believe that even if I execute an
insert statement via the database cursor the transaction management will
still take place, is this correct?

Cheers,
Chris

On Mon, Jun 8, 2009 at 8:11 AM, Karen Tracey  wrote:

> On Sun, Jun 7, 2009 at 7:44 PM, ChrisStoyles  wrote:
>
>>
>> Hi All,
>>
>> I just wanted to quickly reach out to the group for ideas as to why I
>> cannot get this to work:
>>
>> @transaction.commit_manually
>> def some_view(request):
>># some view logic goes here
>>
>>sid = transaction.savepoint()
>>le = models.LogEntry()
>>le.message = 'A test log message'
>>le.save()
>>transaction.savepoint_commit(sid)
>>
>>transaction.rollback()
>>
>> My database back end is Postgres 8.3 and the engine I am using is
>> postgresql_psycopg2. Any ideas as to why my LogEntry would not be
>> committed to the database? I am not getting any exceptions being
>> raised, the code executes as though it has all worked perfectly.
>>
>
> I've not played with savepoints but the behavior you describe matches what
> the docs say:
>
> http://docs.djangoproject.com/en/dev/topics/db/transactions/#savepoints
>
> Specifically, savepoint_commit updates the savepoint to include operations
> since the savepoint was created, but it does not actually commit operations
> at that point.  After you have done a savepoint_commit, a savepoint_rollback
> for that savepoint will not roll back the operations you hae committed for
> the savepoint.  However, an entire transaction rollback, which is what you
> call, will roll back the whole transaction, including your savepoint
> "committed" ones.
>
> As the doc describes it, savepoints are a tool to allow for finer-grained
> rollback.  You appear to be trying to use them for finer-grained commit,
> which I don't think is what they are intended to provide.
>
> Karen
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Logging to Database while using @transaction.commit_manually decorator

2009-06-07 Thread Karen Tracey
On Sun, Jun 7, 2009 at 7:44 PM, ChrisStoyles  wrote:

>
> Hi All,
>
> I just wanted to quickly reach out to the group for ideas as to why I
> cannot get this to work:
>
> @transaction.commit_manually
> def some_view(request):
># some view logic goes here
>
>sid = transaction.savepoint()
>le = models.LogEntry()
>le.message = 'A test log message'
>le.save()
>transaction.savepoint_commit(sid)
>
>transaction.rollback()
>
> My database back end is Postgres 8.3 and the engine I am using is
> postgresql_psycopg2. Any ideas as to why my LogEntry would not be
> committed to the database? I am not getting any exceptions being
> raised, the code executes as though it has all worked perfectly.
>

I've not played with savepoints but the behavior you describe matches what
the docs say:

http://docs.djangoproject.com/en/dev/topics/db/transactions/#savepoints

Specifically, savepoint_commit updates the savepoint to include operations
since the savepoint was created, but it does not actually commit operations
at that point.  After you have done a savepoint_commit, a savepoint_rollback
for that savepoint will not roll back the operations you hae committed for
the savepoint.  However, an entire transaction rollback, which is what you
call, will roll back the whole transaction, including your savepoint
"committed" ones.

As the doc describes it, savepoints are a tool to allow for finer-grained
rollback.  You appear to be trying to use them for finer-grained commit,
which I don't think is what they are intended to provide.

Karen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Logging to Database while using @transaction.commit_manually decorator

2009-06-07 Thread ChrisStoyles

Hi All,

I just wanted to quickly reach out to the group for ideas as to why I
cannot get this to work:

@transaction.commit_manually
def some_view(request):
# some view logic goes here

sid = transaction.savepoint()
le = models.LogEntry()
le.message = 'A test log message'
le.save()
transaction.savepoint_commit(sid)

transaction.rollback()

My database back end is Postgres 8.3 and the engine I am using is
postgresql_psycopg2. Any ideas as to why my LogEntry would not be
committed to the database? I am not getting any exceptions being
raised, the code executes as though it has all worked perfectly.

Thanks,
Chris

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---