Gluing together functions on a closed subvariety I'm trying to get an intuition for what sheafification does. I came across a passage from Perrin's algebraic geometry book about closed subvarieties.
If says that if X is an algebraic variety and Y is a closed subvariety, we can inherit a sheaf on Y from X. It suggests the natural thing to do would be to define:
$O'(V) := \{ f : V \rightarrow K | \text{there is an open } U \in X \text{ such that } U \cap Y = V \text{ and } g|_V = f \text{ for some } g \in O_U \}$
And then it goes on to claim that this is typically not a sheaf, but merely a presheaf, and that the correct thing to do is to sheafify it.
I was trying to justify this last line by finding a counterexample to the gluing axiom. This is what I came up with:
Let $X = \mathbb{A}^2$, let $Y = \mathbb{V}(xy)$. 
Then let $U_1 = D(x)$ and $U_2 = D(y)$, which forms a cover of the open subset $Y - {(0,0)}$ of $Y$. Define $f_1 = 0$ and $f_2 = 1$, which are elements of $O'(U_1)$ and $O'(U_2)$ respectively. They have no overlap, since their would-be intersection at the origin has been left out. But when you glue them together, you seem to run into trouble near the origin. (Informally, the polynomial's value seems to approach both $0$ and $1$ as you approach the orign. Less informally, the density of this open set in $Y$ ought to allow you to extend the polynomial to the origin in two distinct ways).
My question is simply, is my analysis above valid? I feel like I may have overlooked some assumption somewhere.
If it is valid, then what function do you get when you glue together these two functions? 
If I made a mistake somewhere, could I get some guidance towards a true counter-example?
 A: Consider $X=\mathbb P^2=\mathbb P^2_{x:y:z}$ , the projective plane over some algebraically closed field $k$,  and $Y=Y_0\cup Y_1\subset X$,  where $Y_0$ is the line $x=0$ and $Y_1$ is the point $Y_1=\{(0:1:0)\}$.
The variety $Y=Y_0\sqcup Y_1$ is the disjoint union of its open subsets $Y_0, Y_1$ and we have  $f_0=0\in \mathcal O'(Y_0)$ and $f_1=1\in \mathcal O'(Y_1)$.
The gluing condition is certainly vacuously satisfied but nevertheless there is no $f\in  \mathcal O'(Y)$ with $f\vert Y_i=f_i$.
Indeed I'll show below that every neighbourhood $U$  of $Y$ ( $Y\subset U\subset \mathbb P^2$) is of the form $\mathbb P^2\setminus F$ with $F$ finite, so that $\mathcal O(U)=\mathcal O(\mathbb P^2)=k$ by Hartogs's theorem (or algebraically by normality of $\mathbb P^2$) and thus $\mathcal O'(Y)=k$.
But why is $U$ of the claimed form?
Because the complement $Z=\mathbb P^2\setminus U$ of $U$ is included in $\mathbb P^2\setminus Y_0\cong \mathbb A^2$ and thus cannot contain a closed curve $C\subset \mathbb P^2$, so that this complement consists of just a finite set of points: $Z=F=\{p_1,\dots,p_r\}$. 
The above is a small modification (I have avoided using Bézout's theorem) of Perrin's beautiful example in his book, page 46. 
A: EDIT: Incorrect
Your analysis is correct. Letting $U = U_1 \cup U_2$, we do indeed have a regular function on $U$ that is $0$ on $U_1$ and $1$ on $U_2$ (it is locally rational on $U$). There is clearly no regular function on $\mathbb{A}^2 \supseteq Y$ that restricts to our 'weird function'. However, if we sheafify the naive presheaf then such a section is allowed
