What's the proper way to take a Groebner basis with respect to a quotient polynomial ring? Suppose I have the quotient ring $R=\mathbb{Q}[x,y]/I$ for some ideal $I$, and I want to find a Groebner basis for another ideal $J\subseteq R$. When computing the basis, does it make a difference if I consider $J$ as a subset of $\mathbb{Q}[x,y]$, find a basis, then quotient by $I$ vs. finding the basis in $R$ and 'quotienting' as I go along, for lack of a better word.
For reference, I'm trying to do this computation in Sage, and they seem to be giving incompatible answers:
R.<x,y> = PolynomialRing(QQ)
Rq = R.quotient([x*y-1])

ideal1 = Rq.ideal([2*x^2 - 4*y + 1, 3*x^3-2*x^2+y^2-1])
ideal2 = R.ideal([2*x^2 - 4*y + 1, 3*x^3-2*x^2+y^2-1])
print(ideal1)
print(ideal2)
print(ideal1.groebner_basis())
print(ideal2.groebner_basis())
print(x*y in ideal2.groebner_basis())

gives the output:
Ideal (2*xbar^2 - 4*ybar + 1, 3*xbar^3 - 2*xbar^2 + ybar^2 - 1) of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x*y - 1)
Ideal (2*x^2 - 4*y + 1, 3*x^3 - 2*x^2 + y^2 - 1) of Multivariate Polynomial Ring in x, y over Rational Field
[1]
[y^3 - 319/4*y^2 + 45/8*x + 51*y - 9/2, x^2 - 2*y + 1/2, x*y + 1/6*y^2 - 1/4*x - 2/3*y]
False

so the ideal in the quotient ring is $\langle 1\rangle$, but in the original ring $\mathbb{Q}[x,y]$, it's that big mess of three polynomials. Further, $xy$ isn't in the ideal in the original ring, which suggests (to me) that I wouldn't get the same ideal if I took the quotient of the basis. Which of these is the 'right' basis? Or is my understanding of something a bit off?
I've also tried using a few different monomial orderings in the quotient ring, but that hasn't led to any progress either.
 A: I am trying to give an answer, for this, i need to clarify some points during the answer. In the OP, the ideal $J$ appears once as an ideal in a quotient ring of the polynomial ring (anneau) $A=\Bbb Q[x,y]$, then as an ideal in $A$. This is maybe the point causing problems, so i will restate, hoping to hit the point of the question.

Let $R$ be the ring $R=\Bbb Q[x,y]$. Let $I,J$ be two ideals of $R$. Then we have the chains of inclusions (injections):
$$
\begin{aligned}
&0\to I\to I+J\ ,\text{ and}\\
&0\to J\to I+J\ .
\end{aligned}
$$
Passing to quotients of $R$ we obtain morphisms (surjections):
$$
\begin{aligned}
&R\to R/I\to R/(I+J)\ ,\text{ and}\\
&R\to R/J\to R/(I+J)\ .
\end{aligned}
$$
The $R/I$-module $(I+J)/I$ may be considered an ideal.
(The $R/J$-module $(I+J)/J$ may be considered an ideal.)
Let $Q=$Rq be the quotient mentioned in the OP.
Then we have isomorphisms:
$$
\underbrace{\frac{R/I}{(I+J)/I}}_{\displaystyle=\frac Q{(I+J)/I}}\cong \frac R{I+J}\cong \frac{R/J}{(I+J)/J}\ .
$$

Now i am trying to understand the question inside of the last quotient ring(s), based on the given example. We start explicitly with:
$$
\begin{aligned}
R &= \Bbb Q[x,y]\ ,\\
I &= (\ xy-1\ )\ ,\\
Q &= A/I\ ,\\
J &= (\ 2x^2 - 4y + 1\ , \ 3x^3 - 2x^2 + y^2 - 1\ )\ .
\\
&\qquad\text{ Then:}
\\
I+J &= (\ xy-1\ ,\ 2x^2 - 4y + 1\ , \ 3x^3 - 2x^2 + y^2 - 1\ )\ .
\end{aligned}
$$
(I am using I instead of ideal1 and J instead of ideal2.)
We consider the ideal "generated by $J$" inside the quotient $Q=A/I$. Strictly speaking we map $J$ to $Q=A/I$, and consider the image as an ideal. This ideal is $(J+I)/I$.
The code from the OP is building a Groebner basis now for this ideal of $Q$.
Well, i am modest here, any system of generators is enough for this discussion now. One such basis may be the union of the given generators for $I$ and $J$. And taking them modulo $I$ makes the $I$-generators zero in the quotient, so the $Q=A/I$-ideal $(J+I)/I$ is generated by $(xy-1)$ modulo $I$. OK, now we can try to "do more", and ask for a Groebner basis. Let us type some code for the story so far.
R.<x,y> = PolynomialRing(QQ, 2)
I = R.ideal(x*y - 1)
J = R.ideal([2*x^2 - 4*y + 1, 3*x^3 - 2*x^2 + y^2 - 1])
Q.<X,Y> = R.quotient(I)
print(f'Q is the ring:\n{Q}')
print(f'Q(x), Q(y) are now {Q(x)}, {Q(y)}\n')
# so X, Y are the images of x, respectively y in Q = R/I
JQ = Q.ideal(J.gens())
print(f'The ideal JQ is:\n{JQ}\n')
# so already we have other generators for JQ = (J+I)/I 
print(f'... the generators of JQ are:\n')
for gen in JQ.gens():
    print(f'    {gen}')
print(f'\nJQ has the groebner pasis:\n{JQ.groebner_basis()}')

We copy+paste into the sage interpreter, obtain...
Q is the ring:
Quotient of Multivariate Polynomial Ring in x, y
    over Rational Field by the ideal (x*y - 1)
Q(x), Q(y) are now X, Y

The ideal JQ is:
Ideal (2*X^2 - 4*Y + 1, 3*X^3 - 2*X^2 + Y^2 - 1)
    of Quotient of Multivariate Polynomial Ring in x, y
    over Rational Field by the ideal (x*y - 1)

... the generators of JQ are:

    2*X^2 - 4*Y + 1
    3*X^3 - 2*X^2 + Y^2 - 1

JQ has the groebner pasis:
[1]

The "other way" from the OP is not so clear for me.
We start with $J$, ideal in $R$. Then pick the Groebner basis of $J$.
Then we have to pass somehow to the quotient modulo $I$.
When done explicitly as above, we obtain the generator $1$.
We can also do "this" at $R$-level, considering the ideal
$K=I+J$ with generators the union of the generators for $I,J$,
then asking for a Groebner basis of $K$. Then passing to the quotient.
We obtain a new ideal of the quotient, let us denote it by KQ in the code.
In a dialog with the sage interpreter, this is in the given example...
sage: K = R.ideal(I.gens() + J.gens())
sage: K
Ideal (x*y - 1, 2*x^2 - 4*y + 1, 3*x^3 - 2*x^2 + y^2 - 1)
    of Multivariate Polynomial Ring in x, y over Rational Field
sage: K.groebner_basis()
[1]

So there is no difference. Both ways are the same.
We can consider also the ideal KQ:
sage: KQ = Q.ideal(K.gens())
sage: KQ
Ideal (0, 2*X^2 - 4*Y + 1, 3*X^3 - 2*X^2 + Y^2 - 1)
    of Quotient of Multivariate Polynomial Ring in x, y
    over Rational Field by the ideal (x*y - 1)

(As seen, the $I$-generator goes to zero when passing to the generators of KQ.)

So what does in an "unexpected" way the code in the OP? (In this new notation, that is more structural, seen from where i am staying now.)
I am really not expecting to see $xy$ in $J$, so also not in the small list of elements of a Groebner basis of $J$. Even $XY$ is only "by chance" in the Groebner basis of $K$, since $XY=1$ and $1$ is by chance computed as the only generator in the Groebner basis of $K$.
sage: x*y in J
False
sage: x*y in K
True
sage: X*Y in KQ
True
sage: x*y in J.groebner_basis()    # there is no chance for this, since xy not in J
False
sage: X*Y in KQ.groebner_basis()
True
sage: KQ.groebner_basis()
[1]
sage: X*Y
1

